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 Ninjaoboy · Jul 10, 2011 at 04:50 AM · rigidbodycar

add force get stronger over time slow.

i am making a car and i need it to speed up slowly so i have tried putting a * time.deltatime but that didn't work, i did make one huge script that had like 20 if staments so that every time the force would get stroger, but this was a pain because it take a lot of work to do a little tweak so how could i make this better.

   var gravity = 20000;
     var GroundGravity = 1000;
     var Forward = 10000;
     var reverse = 9000;
     var speed : float;
     var Car: Transform;
     
     
     
     
     
     function FixedUpdate () {
     
     speed = rigidbody.velocity.magnitude;
     Time.timeScale = 1;
     
     if(groundtrigger.triggered==0)
     {
     rigidbody.AddForce(Vector3.up * -gravity);
     }
     
     if(groundtrigger.triggered==1)
     {
     rigidbody.AddForce(Vector3.up * -GroundGravity);
     }
     
     
     
     
     
     
     if(Input.GetKey("w")&& (groundtrigger.triggered==1))
     {
     Car.rigidbody.AddForce(transform.forward * Forward);
     }
     
     
     
     
     
     
     if(Input.GetKey("s") && (groundtrigger.triggered==1) && (speed <50))
     {
     rigidbody.AddForce(Car.transform.forward * -reverse);
     }
     
     if(Input.GetKey("d") && (groundtrigger.triggered==1) && (speed > 1))
     {
     rigidbody.AddTorque(Car.transform.up * turnSpeed);
     }
     
     
     if(Input.GetKey("a") && (groundtrigger.triggered==1) && (speed > 1))
     {
     rigidbody.AddTorque(Car.transform.up * -turnSpeed);
     }
     
     }
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 Dreamblur · Jul 10, 2011 at 06:50 AM 0
Share

Force, in Unity, is representative of the acceleration of a rigidbody in motion. When you say you want to increase the force over time, you're basically saying you want the acceleration of an object in motion to change over time, or more specifically, you want the object to have a constant non-zero jerk. While limiting and manipulating the jerk of a moving object has various applications in real life, there is really no practical reason to touch it in a video game. If you were building a simulation for NASA, then I would be inclined to believe that you would need access to the jerk, but if that was the case, you wouldn't be using a free game engine to achieve your purposes.

I believe what you really want is to give the object a constant acceleration so that its velocity would gradually increase or decrease depending on the situation. The thing is, AddForce already does that. By applying a constant amount of force (which like I said is representative of acceleration) every frame, the velocity of an object gradually changes. You just need to know when and how to effectively apply that force to fulfill your objective.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by SilverTabby · Jul 10, 2011 at 05:29 AM

This is what I would do to add force over time


 if(Input.GetKey("w")&& (groundtrigger.triggered==1))
 {
     Car.rigidbody.AddForce(Car.transform.forward * Forward * Time.deltaTime, ForceMode.Acceleration);
 }





The Key diffrence is the ForceMode.Acceleration. This makes it so that the force is added in the exact same way that gravity wroks: a constant increase in speed.

Keep in mind that acceleration IGNORES the mass of the rigid body, so be careful with using it

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 DavidDebnar · Jul 10, 2011 at 06:59 AM 0
Share

If you wan't to not ignore the mass you could use this

    Car.rigidbody.AddForce(Car.transform.forward * Forward * Time.deltaTime / rigidbody.mass, Force$$anonymous$$ode.Acceleration);

because acceleration = force / mass.

  • $$anonymous$$

avatar image Ninjaoboy · Jul 10, 2011 at 02:47 PM 0
Share

i tried both but it still accelerates to fast and if i make the force lower then it has a very low maximum speed i have been confused on this for a longtime i want it to accelerate SLOWLY like a real car this will get from 0 - 60 in a half a second?

avatar image Dreamblur · Jul 10, 2011 at 09:34 PM 0
Share

@Ninjaoboy You are applying a force of 10000 units/sec to your car. What do you expect?

avatar image
0

Answer by kdubb · Jul 10, 2011 at 04:49 PM

The answer lies in rigidbody.AddForce. As stated in another answer you can use one of the ForceMode's to choose whether the value ignores, or pays attention to, the mass of the rigid body.

Any rigid body that you accelerate will do so with respect to newtonian dynamics (aka "physics"). This means that a rigid body with low mass and zero drag will accelerate almost instantaneously; coincidentally these are the defaults in Unity's rigid body component. So to control the speed of acceleration of the rigid body you need to properly set its mass and drag. Try real world settings for these and play with the numbers from there.

The final thing to take into account is the friction involved. Unity uses physics materials to specify the friction properties of colliders (among other things). These friction properties will also affect the rigid body's acceleration if they are set and actively colliding with any of the rigid body's own colliders. One caveat though is that Unity's WheelColliders ignore these friction properties and use an entirely separate friction model specified in the collider properties (look it up in Unity's documentation if you are using these).

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.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How do I make a car in unity? 1 Answer

WheelColliders Bug Fix 0 Answers

How to set max speed for this car ? 1 Answer

if moving statement 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