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 visumecadroide · May 20, 2018 at 09:42 PM · gravityaddforcespeedcaracceleration

How to reach a specific max speed with AddForce() ?

Hello,
Context : 3D, top view, moving a cube, using gravity.
My end goal is to create car movement with this cube (and whithout wheels).

To move the cube, i am using AddForce() and AddTorque().

 if(maxSpeed < 50)
     rigid.AddForce(direction * acceleration * goForward);

acceleration variable is a fixed value and goForward is an integer equal to 1 or -1.

I would like to have my cube accelerating slowly to reach the maxSpeed but the AddForce() push the cube to a speed (on which i have no control) but is unable to reach the desired maxSpeed.

Even using ForceMode.Acceleration don't work.

How can i do it without using a higher acceleration?

Thanks.

Comment
Add comment · Show 1
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 Harinezumi · May 21, 2018 at 10:30 AM 0
Share

You could try using Force$$anonymous$$ode.VelocityChange as the second parameter of AddForce(). See examples here and here.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Captain_Pineapple · May 20, 2018 at 10:30 PM

Hey there,

first up you want to multiply your added force by Time.deltaTime.

With that you scale the force applied according to the current "framerate". Otherwise you might have different behaviour at inconsistent framerates.

Secondly your problem might be that your rigibody has a "drag"-value. This drag value resembles some kind of combined simulation of effects like air resistance that will, in the end, let your body slow down a bit.

If your force is too small it might be enough to acutally counter the accelleration force.

Also you write that you want to create some kind of car. How do you handle the friction towards the ground? And why don't you want to use wheel collider?

Comment
Add comment · Show 1 · 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 visumecadroide · May 21, 2018 at 10:02 AM 0
Share

I use AddForce() in FixedUpdate(() so it is not required to use Time.deltaTime from what i understand. But i tried to add it and tweaked the value. And there is no difference.

About the drag, apprently, with a low drag, i can reach the desired maxSpeed as you said and i have to increase the mass in order to get a slow acceleration like I want. But, by doing this, when i am turning at high speed, the car/cube slip too much on the side because of the low drag. And I don't want that.
Also, why the Force$$anonymous$$ode.Acceleration don't work?

One way i could do to prevent this is to give a growing acceleration and manage only this increase rate to reach the maxSpeed. So acceleration will not be a fixed value. But I heard that it will mess with the AddForce() values and may create weird behaviour on collision.

About the wheels, i said it's going to be a car but not an usual car. Think of it like a car floating on top of the ground but very close to it. Also, the game will be top down so you will not be able to see the wheels. And in my $$anonymous$$d, if you use wheels for adherence, why I can't use the bottom of the cube ?

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

88 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

Related Questions

Insure that the player can't increase speed when over the speed limit 3 Answers

How do i make the Impulse i give to my Player not be lowered by acceleration of gravity? 1 Answer

Unity car tutorial speed boost 1 Answer

Wheel rotation help cant work out the problem? 0 Answers

Ball Addforce Acceleration Speed 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