Hello,
I’m trying to make objects stop moving when they collide with certain “player power”.
To do so I just make their Rigidbody.isKinematic become True, but I want to save the direction that these objects were going, as well with their speed, to, when I turn off the player power, the objects return moving with the same speed to the same direction.
I imagine that I’ll need to apply certain amount of force in certain angle, but how can I get these values?
Actually, don’t worry about saving the force. Instead, save the velocity, (and if the position may change and you want to revert, save the position as well.) Then when you’re ready for the velocity to resume just use the velocity (a Vector3) property.
e.g.
Vector3 CurrentVelocity = SomeGameObject.GetComponent<RigidBody>().velocity;
//Do stuff
SomeGameObject.GetComponent<RigidBody>().velocity = CurrentVelocity;
@binaryuniverse, thanks for the answer, it can be pretty handy, but how can I get the direction? I’ll try to make a mechanic that the player will be able to redirect the objects trajectory.
Like:
“Stop a cannon ball, redirect it back to the cannon, release.”
After the “Release”, the object must travel at the same speed that it had before being freezed, but in the chosen direction (but, if the player don’t want/can’t, it will just keep the previous direction);