Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
6
Question by Doodle · Sep 08, 2010 at 12:28 AM · movementobjectfunctioncheckmotion

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
20
Best Answer

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;
}
Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Doodle · Sep 11, 2010 at 12:49 AM 0
Share

Thanks Peter!

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

Thanks again!!!! Doodle

avatar image Mark 6 · Jan 12, 2011 at 03:41 PM 0
Share

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

avatar image Peter G · Jan 12, 2011 at 11:02 PM 0
Share

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

avatar image thesfid · May 13, 2014 at 02:44 PM 0
Share

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

avatar image Munchy2007 · May 13, 2014 at 02:53 PM 0
Share

You could also query transform.rigidbody.velocity;

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

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

How can i focus the camera on an object i am working on,How to focus camera setting in unity on an object or assets in my scene 1 Answer

Move object to several locations 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges