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
0
Question by spunktrumpet · Dec 19, 2013 at 02:31 AM · timermove

Move game object over time with GetButtonDown

EDIT fwdi = 1.0f; if (fwdi > 0) {

         amountToMove.y = 1.0f * Time.deltaTime;
         transform.Translate (amountToMove);
         fwdi = fwdi - 1.0f * Time.deltaTime;
         if (fwdi == 0.0f)
         {
             amountToMove.y = 0;
             fwdi = 0.0f;
         }
     }
Comment
Add comment · Show 4
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 -GenericPath- · Dec 19, 2013 at 02:46 AM 0
Share

Try using a for/while loop, So that it increments while the button is pressed. Heres a reference for it

avatar image spunktrumpet · Dec 19, 2013 at 04:20 AM 0
Share

Just updated with what I have now, it moves smoothly however it doesn't stop moving and starts as soon as I press play.

avatar image spunktrumpet · Dec 19, 2013 at 05:55 AM 0
Share

Ok it's moving smoothly now and the distance I want however it is moving too fast. I have an animation that plays for 1 second and I want the movement to last 1 second so they are in time so surely by putting i = 1 then decreasing it by 0.1 every update and moving the object forward 0.1 when i = 0 the object has moved 1. I've Debug.log (i); and i counts down a lot quicker than real time. I've updated with what I have now. I've set Time.timeScale = 1f; yet it still makes no difference. Reading that back didn't much make sense. The time it moves from a to b is much quicker than it should be. This is whilst i = 1;

avatar image Santosh Patil · Dec 19, 2013 at 06:38 AM 0
Share

use "i = i - Time.fixedDeltaTime;" ins$$anonymous$$d of "i = i - 0.1f"

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Santosh Patil · Dec 19, 2013 at 05:15 AM

Check your Update function, you added ";" after () remove that. And try below code instead of do...while loop

 if(i >= 0.1f)
         {
             amountToMove.y = 0.1f;
             transform.Translate (amountToMove);
             i = i - Time.fixedDeltaTime;
         }
Comment
Add comment · Show 2 · 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 spunktrumpet · Dec 19, 2013 at 07:21 AM 0
Share

I've got it sorted basically now, the problem was I had the same script attached to a prefab object that wasn't in the scene, I deleted the prefab and now the time is back to normal (actually counts in seconds). However it works fine up to the tiny detail that the object moving actually moves a tiny bit further than it should. I'm guessing that's because in the check function it doesn't stop moving exactly when i = 0, the debug log shows it stopping at -0.01352722, although this may seem insignificant it affects what I'm trying to do. Is there a way to stop it dead one 0.0? I've updated with what I have now.

avatar image spunktrumpet · Dec 19, 2013 at 07:23 AM 0
Share

Also using i = i - Time.fixeddeltatime. produces worse results. and using i = i - Time.deltaTime is the same as my problem now. The amount actually moved is + 0.02 ontop of the 1.0f. This is making a noticeable difference.

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

19 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

Related Questions

Timer running down too quickly 1 Answer

A node in a childnode? 1 Answer

Switching Cameras at runtime 1 Answer

C# move main camra via mouse position on boarders around screen script for RTS Game 0 Answers

How can i display a pdf file in a unity scene ? 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