Before updating to Windows 10 you may need to return your Pro license. More information here

Check object for motion

Is there a prebuilt function that checks if an object is in motion? A function that checks x,y,z tranform to tell if the object is in motion or at rest?

If not, any ideas on how to acomplish this task?



more ▼

asked Sep 08, 2010 at 12:28 AM

avatar image

53 3 2 9

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

1 answer: sort voted first

If you have a rigidbody, then you can do Rigidbody.IsSleeping() to check if your rigidbody is sleeping

If you are using a Character Controller, then checking to see if CharacterController.velocity == Vector3.zero;

Or, you can manually save a Vector3 every frame that remembers the last position. Something like:

function Update () {
     curPos = position;
     if(curPos == lastPos) {
         print("Not moving");
     lastPos = curPos;
more ▼

answered Sep 08, 2010 at 01:38 AM

avatar image

Peter G
18.7k 35 101 222

Thanks Peter!

I will test out the Rigidbody.IsSleeping() function to see if it will work...

Thanks again!!!! Doodle

Sep 11, 2010 at 12:49 AM Doodle

Is there a way to check all gameobjects in the scene to see if they are moving ?

Jan 12, 2011 at 03:41 PM Mark 6

Yes, just iterate through all the objects in your scene i.e. sceneObjects = FindObjectsOfType(GameObject); for(var gB : GameObject in sceneObjects) { //use above info }

Jan 12, 2011 at 11:02 PM Peter G

I couldn't get rigidbody.isSleeping() to work for me, but comparing curPos to lastPos works like a charm. Thanks!

May 13, 2014 at 02:44 PM thesfid

You could also query transform.rigidbody.velocity;

May 13, 2014 at 02:53 PM Munchy2007
(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



Answers and Comments



asked: Sep 08, 2010 at 12:28 AM

Seen: 9595 times

Last Updated: May 13, 2014 at 02:53 PM