Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
2
Question by goo-muffin · Jan 17, 2013 at 12:40 PM · gameobjectmovebooleanitween

check if object is moving

Hi!

I use iTween a lot. But is there a way to check if an object is currently standing still or is moving?

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

4 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by Vonni · Jan 17, 2013 at 02:14 PM

Is the object a rigidbody? Or some object you might set into motion yourself? If it's a rigidbody you might be able to check if its "sleeping" or not. Else if you issued the movement, you might be able to predetermine whether its in motion or not with some clever scripting. Last solution would be to have a function that checks:

 function IsThisObjectMoving (object : Transform) : boolean {
     var sek0pos : Vector3;
     var sek1pos : Vector3;
 
     sek0pos = object.position;
     yield(WaitForSeconds(1.0); // Wait one second
     sek1pos = object.position;
 
     if(sek1pos - sek0pos).sqrMagnitude > 0.1)
        return true;
     else
        return false;
 }
Comment
Add comment · 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
3

Answer by Jeffom · Jan 17, 2013 at 01:55 PM

well you could make something like this

 ObjectA : Monobehaviour
 {
     public bool bIsOnTheMove = false;

     private IEnumerator CheckMoving()
     {
         Vector3 startPos = transform.Position;
         yield return new WaitForSeconds(1f);
         Vector3 finalPos = transform.Position;

         if( startPos.x != finalPos.x || startPos.y != finalPos.y
             || startPos.z != finalPos.z)
           bIsOnTheMove = true;

     }
 }

you can use a while to keep the checking true, but it would be wise to only turn use the coroutine when you need to check the object. *this may not compile it's just a pseudo code to show the point i'm trying to make

Comment
Add comment · 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
2

Answer by JDSaraiva · Jun 06, 2014 at 10:48 AM

I came up with this solution, worked best in my case.

 function calcSpeed() {
             prevPos = personagem.transform.position;
             yield WaitForSeconds(0.5);
             actualPos = personagem.transform.position;
             
             if (prevPos == actualPos) print("character stoped");
             if (prevPos != actualPos) print("character on the move");                
 }
Comment
Add comment · 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
2

Answer by vikitosss · May 08, 2016 at 02:17 PM

jdsaraiva +1. I like this...

 var IsMoved = false;
 
 function moveCheck() {
     var p1 = transform.position;
     yield WaitForSeconds(0.5);
     var p2 = transform.position;
     
     IsMoved = (p1 != p2);             
     // or : IsMoved = (p1 == p2);
 }




Comment
Add comment · 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

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

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How would I go about moving a group of objects as one using iTween? 1 Answer

Can I move a component from one GameObject to another in script? 1 Answer

Moving object to specific location 1 Answer

Itween gradual jump 2d 1 Answer

Move object, then destroy it. 1 Answer


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