x


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?

Thanks

Doodle

more ▼

asked Sep 08 '10 at 12:28 AM

Doodle gravatar image

Doodle
43 1 1 6

(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 '10 at 01:38 AM

Peter G gravatar image

Peter G
17.3k 22 51 149

Thanks Peter!

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

Thanks again!!!! Doodle

Sep 11 '10 at 12:49 AM Doodle

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

Jan 12 '11 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 '11 at 11:02 PM Peter G
(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:

x2136
x1556
x708
x137
x115

asked: Sep 08 '10 at 12:28 AM

Seen: 5229 times

Last Updated: Sep 08 '10 at 12:28 AM