x


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;
more ▼

asked Oct 27 '11 at 12:45 AM

icetrap gravatar image

icetrap
16 1 1 1

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

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.

more ▼

answered Oct 27 '11 at 06:22 AM

green_core gravatar image

green_core
91 2

worked great thanks!

Oct 27 '11 at 04:33 PM icetrap
(comments are locked)
10|3000 characters needed characters left

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);

more ▼

answered Oct 27 '11 at 02:55 AM

fractyja gravatar image

fractyja
21 1 2 2

(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Oct 27 '11 at 04:06 AM

SirMacJefferson gravatar image

SirMacJefferson
109 18 20 24

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x110
x11

asked: Oct 27 '11 at 12:45 AM

Seen: 1460 times

Last Updated: Oct 27 '11 at 04:33 PM