- Home /
Clearing out an objects force when trying to teleport it.
I am currently writing some logic that after the game has finished I want to reset all of our current game objects back to their starting locations. I can get the objects to get teleported back to their correct starting locations but it seems after the game countdown and I reenable their activity they will thrust forward. Or in what ever direction they were heading when I teleported it. Is there a way to clear an objects force?
This is how I am teleporting my object.
playerObject.transform.position = startingPosition.transform.position;
playerObject.transform.rotation = startingPosition.transform.rotation;
Answer by green_core · Oct 27, 2011 at 06:22 AM
To clear forces you need to set rigidbody.velocity and rigidbody.angularVelocity to zero.
rigidbody.velocity = Vector3.zero;
rigidbody.angularVelocity = Vector3.zero;
If you forget about angular velocity then objects will continue rotating.
Worked great for me for a different purpose. I tried to figure this out myself for about an hour but no luck. Thanks for the info.
Answer by YJack · Oct 27, 2011 at 02:55 AM
You can use change your velocity with: rigidbody.velocity = Vector3.zero; But you might want to destroy and re-instantiate your object with: Destroy (gameObject); Instantiate (prefab, Vector3.zero, Quaternion.identity);
Answer by SirMacJefferson · Oct 27, 2011 at 04:06 AM
Do they have rigidbodies attached to them and are you manipulating their velocity/adding force to them in any way? If so, just set their velocity to Vector3.zero like so:
rigidbody.velocity = Vector3.zero;
If you're manipulating their position without use of rigidbodies, then it must have something to do with your system.
Your answer
![](https://koobas.hobune.stream/wayback/20220613022849im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
how to get child objects transform in arry ? 1 Answer
Flashlight 1 Answer
Same script not working on next level 0 Answers