More Explanation
i want to make a moving and rotating ball stop moving and rotating by making that ball kinematic Rigid body but after some time i want that body to move with same velocity and rotation as well…
i can make the game object stop moving and rotating by doing the velocity zero and angular velocity zero but i don’t know how to save the parameters linear velocity and and angular velocity and direction and apply them latter or the same object. help me because i am new in Games development and Thanks in Advance .
You’re already doing it without realizing you’re doing it. By setting the velocity/angular velocity to zero, you’re essentially overriding it to be a value. Simply do the same thing again when you want to start it back up again.
Create two variables that store the objects velocity and angular velocity. Right before you stop the object, assign the current velocity and angular velocity of the object to these variables and use them when you want the object to start moving again.
private Vector3 savedVelocity;
private Vector3 savedAngularVelocity;
private void StopObject()
{
// Save the current values
savedVelocity = objectRigidbody.velocity;
savedAngularVelocity = objectRigidbody.angularVelocity;
// Stop the object
objectRigidbody.velocity = Vector3.zero;
objectRigidbody.angularVelocity = Vector3.zero;
}
private void StartObject()
{
// Using the saved variables, reassign the values
objectRigidbody.velocity = savedVelocity;
objectRigidbody.angularVelocity = savedAngularVelocity;
}