I have a "Hand" GameObject controlled by a Leap Motion Controller. The Hand despite having RigidBody and Box Collider just seemingly moves with no regards to physics (transform translate movement I suppose). So it clips through other Rigidbody objects.
I'm trying to pseudo-introduce physics to it. I created a second GameObject "HandClone" (with Rigidbody and Box Collider) that copies the first Hand
position but moves with actual physics. HandClone script:
private void FixedUpdate()
{
rb.MovePosition(targetTransform.position);
rb.MoveRotation(targetTransform.rotation);
}
Now HandClone goes where Hand goes, and HandClone is successfully bumping into other objects.
However, when HandClone gets stopped by something, Hand
still keeps moving past HandClone and clips into the other objects, like before.
Now I am thinking that the way to solve this is to constrict Hand
's movements to the bounds of HandClone
so that finally Hand
will stop clipping through objects. But how can this be achieved, would that even work, and is there a better way? Will movement streamed from Leap Motion Controller even respond to scripts like that?
__
Edit: I've now decided to hide Hand and place HandClone where Hand was.
But my script for HandClone to copy Hand's movements is making HandClone fly all over the place. Here's the script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class clone1 : MonoBehaviour
{
private Rigidbody rb;
public GameObject target;
void Start()
{
rb = this.GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
}
private void FixedUpdate()
{
Vector3 newRotation = new Vector3(target.transform.eulerAngles.x + 8.5f, target.transform.eulerAngles.y - 172.78f, target.transform.eulerAngles.z - 94.02f);
rb.MoveRotation(Quaternion.Euler(newRotation));
}
}
The reason why I am adding those float numbers is because when the game isn't playing, those numbers are what make HandClone sit in the correct position, so I thought it would help with alignment in playmode. But HandClone is just flying everywhere regardless. Any advice with making the HandClone stay attached to the avatar's wrist would help.