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 Genosis · Mar 26, 2014 at 03:24 AM · scripting problemmovementfps

How make movement speed constant with FPS?

I am trying to code a movement similar to Flappy bird where when I click the button the player jumps.

However whenever the FPS changes the movement change, I understand this is because I am using update() to move the character.

I was taught that if you multiply a value with Time.deltaTime it wouldn't change. But alas it seems to persist, and there are times when the time.deltaTime value spikes.

What do I do in this scenario?

The code I am using basically gives the player a constant downward acceleration. This makes the velocity goes to the negative. When I want the player to jump, I give it a positive velocity so it flies upwards. Essentially, Flappybird.

 void Update () {
     transform.position = new Vector3(
     transform.position.x,
     transform.position.y + (flightDropVelocity * Time.deltaTime),
     transform.position.z);
     flightDropVelocity = flightDropVelocity + flightDropAcceleration;
 }


 public void Flight(){
     flightDropVelocity = 250f;
 }
Comment
Add comment · Show 8
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 Sildaekar · Mar 26, 2014 at 03:27 AM 0
Share

Use FixedUpdate when working with physics.

avatar image Genosis · Mar 26, 2014 at 03:32 AM 0
Share

I am not really using physics though? I thought you only use it when dealing with rigidbody stuff. I am just making a constant deceleration of values ish.

Unless you mean this will fix all issues

avatar image Adamcbrz · Mar 26, 2014 at 04:01 AM 0
Share

What kind of frame rates are you getting. I believe time.deltaTime does as mentioned as long as frame rate stays relatively consistent. If you are having huge spikes in fps it will be hard to keep it looking right.

avatar image Zeuslightning125 · Mar 26, 2014 at 04:16 AM 0
Share

If all else fails, you could make another vector 3 deter$$anonymous$$ing where you want it to go and go to it using -newlocation- = Vector3.$$anonymous$$oveTowards (-location-, -destination-, -speed- * Time.deltaTime);

avatar image Genosis · Mar 26, 2014 at 04:21 AM 0
Share

Yeah it does get spikes at times. So I have no idea what to do, I am at a loss at the moment.

Show more comments

1 Reply

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

Answer by fholm · Mar 26, 2014 at 09:06 AM

You are applying the delta time at the wrong place, this is what you want most likely:

 void Update () {
     flightDropVelocity = flightDropVelocity + (flightDropAcceleration * Time.deltaTime);
     transform.position = new Vector3(transform.position.x, transform.position.y + flightDropVelocity, transform.position.z);
 }
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 Genosis · Mar 26, 2014 at 09:13 AM 0
Share

I want it to move consistently without the framerate affecting it, so should I use the Time.deltaTime or not?

avatar image fholm · Mar 26, 2014 at 09:19 AM 0
Share

Yes you should use Time.deltaTime, the code you have is correct.

avatar image Genosis · Mar 26, 2014 at 09:30 AM 0
Share

If so I am absolutely bewildered because it is not working as intended. Sigh. Thanks a lot anyway.

avatar image fholm · Mar 26, 2014 at 09:50 AM 0
Share

I mean, the logic you are using doesn't give you constant speed downwards/upwards it gives you constant acceleration, which is probably not what you want. It is not dependant on framerate tho.

avatar image fholm · Mar 26, 2014 at 09:51 AM 0
Share

Actually, I looked closer, this is probably what you want:

 void Update () {
     flightDropVelocity = flightDropVelocity + (flightDropAcceleration * Time.deltaTime);
     transform.position = new Vector3(transform.position.x, transform.position.y + flightDropVelocity, transform.position.z);
 }
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

26 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

Related Questions

The Camera is facing backwards of the Character 1 Answer

Flicker at the end of rotate 90° with animations 3 Answers

FPS Standard Asset movement when switching to android platform 0 Answers

Question about moving an object technique 3 Answers

How to make a number Whole after SmoothDamp ? 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