Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by scarecrow569 · Sep 15, 2018 at 12:01 AM · positioningvector3.movetowards

I'm getting some very strange movements from an object position

The station Gameobject teleports to the almost the center of the scene when the function is called. When it should move slowly to the right. The function is called from the startup() with a on click button listener.

I am confident it has something to do with the deltaTime. But I can't seem to solve it.

 void GoToBelt(GameObject station)  
     {

         float stationMovingSpeed= 1;
         Vector3 stationUndocked = new Vector3(-16, 3.2f, 0);
             
         float step = stationMovingSpeed * Time.deltaTime; 
 
         station.transform.position = Vector3.MoveTowards(transform.position, stationUndocked, step);
   
     }


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
0
Best Answer

Answer by tormentoarmagedoom · Sep 15, 2018 at 12:22 AM

Good day.

As i supose this script is not in the station Gameobject because you need to acces it from station.transform... You miss refear to the station inside the MoveTowards function.

Replace with :

 station.transform.position = Vector3.MoveTowards(station.transform.position, stationUndocked, step);

Bye!

Comment
Add comment · Show 3 · 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 scarecrow569 · Sep 15, 2018 at 12:47 AM 0
Share

Thanks I missed that. However now the GameObject moves 1 pixel per click of the button. I would have thought it would move fluidly after 1 click.

avatar image JVene scarecrow569 · Sep 15, 2018 at 01:55 AM 0
Share

You'll need to review what $$anonymous$$oveTowards does. It is like a lerp. The third parameter must be able to transit between 0 and 1, the output of $$anonymous$$oveTowards will be a point between start and end points provided, but in particular can only approach the endpoint as 'step' becomes 1.0.


In your logic, there's no chance of that happening. Time.deltaTime will likely always be 1/60th of a second, meaning that the result will always be the same step. You must increment step from 0 to 1, but your code isn't doing that. $$anonymous$$ake step a member, not a local. Initialize it to zero at the beginning of this motion, and let it increment the calculation of speed * deltaTime, stopping the motion when step reaches the goal of 1.0.

avatar image scarecrow569 JVene · Sep 15, 2018 at 01:58 AM 0
Share

I think because I was calling it from a button click listener it only fires once per click. It works fine in the update function. So now I'm knee deep in IEnumerator's and while loops.

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

89 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

GUI changes when game runs full screen 2 Answers

placing children objects in different places 1 Answer

Animation from actual position instead of animation starting position 0 Answers

Gyroscope default position 2 Answers

Ideas on enemy unit formations solution 0 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