Hi,
I’m new here and developing a game where I control a hand (like in the game black white) that allows me to pick up objects.
I want it not to go through the walls and floor to keep better track of it and I use the following
void OnCollisionEnter(Collision collision) {
if(collision.gameObject.name.Equals("Sphere")){
Debug.Log("collision happened!!");
handSphereCollisionFlag = true;
rigidbody.constraints = RigidbodyConstraints.FreezeAll;
}
if(collision.gameObject.name.Equals("Ground")){
rigidbody.constraints = RigidbodyConstraints.None;
rigidbody.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionZ;
}
if(collision.gameObject.name.Equals("LeftWall")){
Debug.Log("left");
rigidbody.constraints = RigidbodyConstraints.None;
rigidbody.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezePositionZ;
}
if(collision.gameObject.name.Equals("RightWall")){
Debug.Log("right");
rigidbody.constraints = RigidbodyConstraints.None;
rigidbody.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezePositionZ;
}
}
And that works, but after I pick up an object (like a sphere, also with collision detection) my hand/sphere gets a velocity or force and i cant move it properly anymore. It gets a velocity or force in the x position. If I make the rigidbody kinematic, the collision detection with the walls doesn’t work anymore…
I also tried setting the velocity to zero in every frame in the FixedUpdate() but has no effect…
Any ideas how to work around this? Many thanks in advance!