- Home /
How to have a cube to fall on fixed rotation?
Hello all,
I'm having a cube in my scene with a rigidbody and I want the player to click the cube, the cube will jump, rotate in the air, fall down to fixed position.
This is the script I use:
void Update ()
{
rb.AddForce((magnet.transform.position - transform.position) * forceFactor * Time.smoothDeltaTime);
if (Input.GetKeyDown(KeyCode.A))
{
jumpingHeight = 200f;
rb.AddForce(0, jumpingHeight, 0);
rb.AddTorque(Random.Range(0, 500), Random.Range(0, 500), Random.Range(0, 500));
transform.rotation = Quaternion.identity;
}
}
Basically I want the cube to fall when all rotation is 0,0,0
I read in answers that rigidbody is hard to control, what would be your approach to this one?
Comment
Answer by xxmariofer · Apr 07, 2019 at 11:41 AM
That type of tasks are usually done with animations, and if you want to do it by code use the transform rather than rigidbodys (you can use movetowards method and lerp for lerping position and rotation), dont use forces that is more difficult more unprecise (without deep physics knowledge) and worse performance