- Home /
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
Answer by Peter G · Sep 08, 2010 at 01:38 AM
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;
}
Thanks Peter!
I will test out the Rigidbody.IsSleeping() function to see if it will work...
Thanks again!!!! Doodle
Is there a way to check all gameobjects in the scene to see if they are moving ?
Yes, just iterate through all the objects in your scene i.e. sceneObjects = FindObjectsOfType(GameObject); for(var gB : GameObject in sceneObjects) { //use above info }
I couldn't get rigidbody.isSleeping() to work for me, but comparing curPos to lastPos works like a charm. Thanks!
Your answer
Follow this Question
Related Questions
Make and object invisible while in motion? (3d) 2 Answers
move object with parabola 0 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Move object to several locations 2 Answers