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 · Sep 17, 2014 at 01:50 PM · rigidbodygravity

Rigid body speed not increasing.

I've got a simple scene set up with a ball with a rigid body attached. When the ball rolls down a slope the speed stays at a constant and doesn't increase and pick up speed over time as it rolls as you assume it would. This is the only piece of code I have attached to it which simply moves it forward.

 if(Input.GetKey("w")){

         rigidbody.AddForce(Vector3.forward * 10);

 }


Is there a simple answer to how to get it to increase in speed based on the enviroment.

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 Bluntweapon · Sep 17, 2014 at 06:41 PM 0
Share

There're some things that might interfere. Frictional forces of the ground, and Drag property of the RigidBody comes to $$anonymous$$d.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by TheDDestroyer12 · Sep 17, 2014 at 02:53 PM

You shouldn't even have to do that. The ball should roll down the slope as soon as you just have a rigidbody attached to it. I don't know why it don't work like that, but to get that code working, you should place it in the update method, like this:

 void Update()
 {
     if(Input.GetKey(KeyCode.W))
     {
         rigidbody.AddForce(0, 0, 10);
     }
 }

That's it. It should work! Good luck!

/TheDDestroyer12

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 spunktrumpet · Sep 17, 2014 at 03:23 PM 0
Share

I have it in a properly formatted script, I just pasted the part which handles the rigid body... Also it does roll down the slope, it just doesn't increase it's speed as it rolls.

avatar image Ebil · Sep 17, 2014 at 03:34 PM 0
Share

Physically based code should go in the FixedUpdate routine. Since thats what FixedUpdate is made for.

avatar image TheDDestroyer12 · Sep 17, 2014 at 06:20 PM 0
Share

@Ebil Okay, didn't actually know that. Thanks!

@spunktrumpet By saying it is in a properly formatted script, that doesn't mean you placed it in the (fixed)update function. You don't actually write that in your question, which makes it hard to know. However, if you did, it's weird that it doesn't work, because I wrote down that code (almost. I wrote "0, 0, 10", ins$$anonymous$$d of "Vector3.forward*10". You could try doing like that) and tested it earlier today, before I posted my answer, and it worked! I don't understand what's wrong. You don't get any errors or warnings?

/TheDDestroyer12

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

25 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

Related Questions

jump script : 2D 1 Answer

A node in a childnode? 1 Answer

Errors with gravity switching... 1 Answer

Movement problem? 0 Answers

How can i make artificial gravity for Kinematic Rigidbody? 3 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