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
1
Question by Shar1ngan · Feb 11, 2013 at 11:10 AM · physicsrigidbodyaddforceforcemode

Addforce - bug with jump

Hello, i write own player controller, use rigidbody and box collider (for 2d game). I use Addfoce for jump.

void FixedUpdate () {
    if (Input.GetButtonDown ("Jump"))
    {
        rigidbody.AddForce(Vector3.up * Jump,ForceMode.Impulse);
    }
}

It work fine, but sometimes player can jump higher than it should. I tried to remove ForceMode or chane to other. I tried to add * Time.deltatime. But nothing helps. What I'm doing wrong?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by MjrDeathAdder · Feb 11, 2013 at 12:44 PM

What I'm using which seems to be working fine is:

void Update() { if(Input.GetButtonDown(KeyCode.Space)){ rigidbody.velocity = new Vector3(0, JumpVelocity, 0); } }

But my assumption is that this is going to be the same. Another thing is maybe collision detection is adding an upward force at the same time. Best of luck.

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 Shar1ngan · Feb 11, 2013 at 01:14 PM 0
Share

Thank you, now it works. But I still do not understand the reason why AddForce do that...

avatar image
0

Answer by deltamish · Feb 11, 2013 at 02:18 PM

  • But I still do not understand the reason why AddForce do that...


The reason to that is when the character is on higher ground His Z axis wiil be more to put in simpler terms

take z =1 as lower ground and take z =2 for higher ground and jumpforce as 2 .When you are in lower ground and when you press jump 1 is multiplied by 2 which is 2.But when you are in higher ground and when you press jump (z =2) 2 will be multiplied by 2 which gives four so as you can see they both are not the same but where as velocity doesnot change wether he is in higher or lower region as long as he is in contact with 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

11 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

Related Questions

Confusion with AddForce with ForceMode.Acceleration 1 Answer

Erratic Physics behaviour while testing in 2 computers 0 Answers

Trying to Understand Rigidbody ForceMode Derivation 3 Answers

Object jumping while moving(with addForce) 0 Answers

add force to object that has 2 different rigid bodies 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