x


Rigidbody.MovePosition performance

Is it a bad idea to have multiple scripts attached to a game object, each of which modifies a particular aspect of the object's position by calling rigidbody.MovePosition? Stated another way: are there undesirable performance implications to calling MovePosition more than once per FixedUpdate?

Also, is it important to avoid calling MovePosition if the x/y/z values are not being modified?

more ▼

asked Jan 11 '10 at 04:20 PM

Ehren gravatar image

Ehren
4.2k 34 43 77

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

1 answer: sort voted first

Well, the more times you call MovePosition the more CPU power it will take, so it is best to use it as few times as possible, store the desired position to move to in a variable which you change during FixedUpdate, and then in the end of your FixedUpdate call MovePosition once using the data from that variable, that will save you some CPU time.

For the same reasons it might be good to check if the position is being altered before you call MovePosition and call it only if it does change.

more ▼

answered Jan 11 '10 at 04:57 PM

TowerOfBricks gravatar image

TowerOfBricks
3.2k 17 25 50

(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:

x1865
x1782
x470

asked: Jan 11 '10 at 04:20 PM

Seen: 2536 times

Last Updated: Jan 11 '10 at 04:20 PM