• 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 /
  • Help Room /
avatar image
0
Question by andracer108 · Sep 21, 2017 at 08:11 AM · physicsforcedragaccelerationhover

Hovercar rigidbody acceleration

Description

I currently have a hovercar working with physics and the script I created is based off of the hovercar tutorial made by Unity themselves. The problem I am having is that the I am finding the acceleration of the hovercar too high and its reaching its top speed quickly. Is there any way I can implement slower acceleration but maintaining control over the vehicle with the current setup I have below?

N.B. I also want this because I want the hovercars to have different attributes like top speed, acceleration, handling, etc.

Info

Tutorial: https://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/hover-car-physics (script can be found under video)

The scripts and rigidbody settings are exactly the same except for some few things:

Rigidbody:

  • Use Gravity is off (I'll explain later)

  • Interpolate is set to Interpolate (since for some reason my hover car stutters without this)

Script:

Check the code comments for the changes (fixed update part only is shown since physics are only done there)

 void FixedUpdate()
         {
             // I added my own fake gravity here
             Vector3 appliedGravityForce = -transform.up * 9.81f;
             carRigidbody.AddForce(appliedGravityForce, ForceMode.Acceleration);
     
             Ray ray = new Ray(carFlyer.position, -transform.up); // used a child object in front of the car as the position to make the detection more accurate
             RaycastHit hit;
     
             if (Physics.Raycast(ray, out hit, hoverHeight * 1.5f)) // made detection be a bit broader
             {
                 float proportionalHeight = (hoverHeight - hit.distance) / hoverHeight;
                 Vector3 appliedHoverForce = transform.up * proportionalHeight * hoverForce;
                 carRigidbody.AddForce(appliedHoverForce, ForceMode.Acceleration);
     
                 Quaternion targetRotation = Quaternion.FromToRotation(transform.up, hit.normal) * carRigidbody.rotation;
                 carRigidbody.rotation = Quaternion.Slerp(carRigidbody.rotation, targetRotation, Time.fixedDeltaTime * 3);
                 // I adjusted the car's angles to the normal of the ground under it
 
                 Debug.DrawRay(ray.origin, -transform.up, Color.cyan); // just some debug stuff
             }
     
             carRigidbody.AddRelativeForce(0f, 0f, powerInput * speed);
             carRigidbody.AddRelativeTorque(0f, turnInput * turnSpeed, 0f);
         }

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

Answer by andracer108 · Jan 21, 2018 at 06:40 PM

Answering myself for the second time on this forum. Quite disappointed with the community really. But anyways, I managed to find a solution quite a while ago to this problem and I just forgot to mention it, so I'll explain it here for future reference and for people who are having the same problem:

The high acceleration and low top speed were coming from the high drag value done in the tutorial. This is because drag means how much air resistance the object has... meaning the higher this value, the more force is being applied opposite to the velocity of the object. This keeps the hovercar from losing its "grip" and being able to turn and move in the new direction. Therefore, this means that there is pretty much no direct solution to this problem. I did find a workaround though.

The workaround included me creating a small intermediate variable where when the user presses "W" to go forward, this variable's value will increase at a certain rate which is being used as a multiplier (between 0 and 1) for a pre-defined variable that is the applied forward force to the car. This makes it so you can control how much acceleration the car can have with any top speed you want. I'll include a snippet below... hope this helps!

 if (Input.GetAxisRaw("Vertical") > 0)
 {
     powerInput = Mathf.Clamp01(powerInput + forwardAcceleration * Time.deltaTime);
 }
 else
 {
     powerInput = Mathf.Clamp01(powerInput - neutralDeceleration * Time.deltaTime);
 }


Variable Key:
powerInput: Value being used to apply as force. Used as a multiplier for the actual force in this case.
forwardAcceleration: pre-defined forward value (the forward acceleration rate)
neutralDeceleration: pre-defined "no-input" value (the deceleration rate for when the user isn't pressing anything)

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

164 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 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

Backspin of Sphere with Rigidbody 0 Answers

What's the best method for pinball-type bumper physics (3D)? 1 Answer

How to make Airplane move forward faster INSTANTANEOUSLY? 1 Answer

Simple vechicle simulation : generating particles at a specific point and applying forces on wheels rather than the body? 0 Answers

Set predicate dice value when rolling 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