- Home /
how can i rotate a rigidbody smoothly,how to rotate a rigidbody in a smooth way
Here's my problem: I'm creating a grabbing/dropping system with physics-based objects, similar to Amnesia. In this system, the grabbed object needs to be able to collide with other objects and walls. While the object is being grabbed, it tries to keep a consistent position and rotation in front of the player, but it will deviate when colliding with other objects. I use this code to move the object toward the target position in front of the player:
rigidbody.velocity = ((target.transform.position - transform.position) Time.deltaTime speed);
This code works fine. The object moves smoothly, and interacts with the environment properly. The problem arises when I try to get the object to properly rotate. These are four different attempts that I have made to rotate the object:
if (!isColliding) { //GetComponent().rotation = Quaternion.Lerp(transform.rotation, hand.transform.rotation, Time.deltaTime amount); //GetComponent().MoveRotation(hand.transform.rotation); //transform.rotation = Quaternion.Slerp(transform.rotation, hand.transform.rotation, 1); //GetComponent().AddTorque((transform.eulerAngles - hand.transform.eulerAngles) Time.deltaTime * speed); }
The problem is that the object's movement is either very choppy or it gets really junky once it interacts with another object, and no matter what I do the object always keeps the reaction force of the rotation so when I release the object it starts rotating like crazy. I was hoping somebody here could help me out, I tried to AddTorque but i really didnt understood how i could use that to make the object rotate to a specific rotation. Thanks for your time
Answer by vladibo · Nov 16, 2018 at 02:17 AM
// catch up by 45 degrees in second - change it if you want faster or slower var comp = GetComponent(); comp.rotation = Quaternion.RotateTowards(comp.rotation, hand.transform.rotation, Time.smoothDeltaTime * 45);
Your answer
Follow this Question
Related Questions
Prevent a fast moving ball from passing through a wall 2 Answers
Can you have an OnTriggerX event with Sleeping rigidbodies? 1 Answer
How can i make my RigidBodyFPSController to move when Is Kinematic is true ? 1 Answer
rigidbody problem !!! 0 Answers
Rigidbody (2D) stays in fixed angle even when colliding 1 Answer