Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Mechlordx · Dec 24, 2013 at 02:37 AM · rigidbodyaddforceacceleration

Rigidbody.AddForce 2d movement without acceleration

I finally have movement working well enough in a game using a Rigidbody and the AddForce function, but I need to have no acceleration or deceleration. Adjusting the drag to a really high number doesn't work because it stops movement all together, or if the character can move then there is still minor acceleration/deceleration. Are there any other Rigidbody functions I should look at for this kind of problem? Is there another way to utilize AddForce that doesn't have this problem? Note a character controller simply will not do, this 2d character just cannot be "encapsulated" for it.

Comment
Add comment · Show 5
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 Mechlordx · Dec 24, 2013 at 05:44 AM 0
Share

rigidbody.velocity.x is not working, I get "cannot modify return value because it is not a variable". I also tried using velocity.set(#,#,#) and that isn't resulting in anything happening

avatar image Invertex · Dec 24, 2013 at 08:00 AM 0
Share

Forgot that you couldn't directly set a single axis of rigidbody. Updated the code to reflect that.

avatar image Mechlordx · Dec 25, 2013 at 04:22 AM 1
Share

i coulda sworn i tried it before, but i tried it again and it worked. thanks

avatar image Invertex · Dec 26, 2013 at 10:58 PM 0
Share

Glad to hear! You should accept an answer on this question btw ;)

avatar image Invertex · Jan 25, 2014 at 10:41 AM 0
Share

Psst, still need to accept an answer! :)

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by aldonaletto · Dec 24, 2013 at 02:45 AM

A possible solution is to directly set rigidbody2d.velocity. If you want to move it horizontally and still keep the gravity effect, for instance, modify only the X component:

 var curVel: Vector2 = rigidbody2d.velocity;
 curVel.x = Input.GetAxis("Horizontal") * 5.0; // max speed = 5
 rigidbody2d.velocity = curVel;

NOTE: You still may experience some acceleration/deceleration due to the internal filtering of GetAxis; if this is undesired, use Input.GetAxisRaw() instead.

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
avatar image
0

Answer by Invertex · Dec 24, 2013 at 02:48 AM

One way would be to simply:

 if ((Input.GetKeyUp("left")) || (Input.GetKeyUp("right")))
 {
     rigidbody.velocity = new Vector3(0,rigidbody.velocity.y,rigidbody.velocity.z);
 }

That way whenever the player stops pressing a movement key, their X axis velocity will come to a stop. (you can add an if grounded statement in there too if you only want that happening on the ground)

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

20 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

Related Questions

Confusion with AddForce with ForceMode.Acceleration 1 Answer

Ball Addforce Acceleration Speed 1 Answer

About Forces and Time.deltaTime 3 Answers

[Solved] Unity rigidbody.addForce ignores time.deltaTime? Possibly just a code bug I cannot find. 0 Answers

Rigidbody falling very slow 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