- Home /
Rigidbody2D adding force vs modifying velocity for character jump
Hey Guys,
I know that there is a lot of question of adding force versus velocity changes, but I'm using the Rigidbody2D from 4.3 version and I have a problem in my jump. For example, I give an initial force to my rigidbody, than if the player hold the button, I add like a small up force each 0.1 seconds. My problem is that The jump curve is not perfect because Each time that I add force, I can see that It makes a little peak in the curve. I was like, I could add less force each time, but if I dont add that much force, I don't see a difference. Then I began investigating modifying velocity directly. I'm still not sure of what is the difference between mRigidyBoddy.AddForce(Vector2.up * 10) and mRigidBody.velocity = mRigidBody.velocity + Vector2.up *10;. If some one could explain the difference clearly that would be great. Also, to fix my jump problem, I saw that in the normal rigidbody class, there was an AddRelativeForce, I don't know if it is the key to my problem. Does anybody has an idea ?
Thanks a lot for your time and have a good day :)
Claude
Hy Claude
did you find a solution to your problem because I have exactly the same I did find something satisfying. I am think about not using rigidbody2d.
Hey there Nicolas,
I am resetting the y velocity and than adding a force after and it worked quite well for me.
Here's an example :
mRigidbody2D.velocity = new Vector2(mRigidbody2D.velocity.x,0); mRigidbody2D.AddForce(new Vector2(0,mJumpForce));
Hope it helps :)
Answer by smallbit · Nov 20, 2013 at 11:45 AM
Given that you have the framework to test, why you don't try yourself the difference between those two. From the physics point of view force and velocity are different magnitudes and in Unity behave way differently for instance when player is in the max height of jump (his velocity approaching to zero) add force will still make him jump (it will be added regardless his state position velocity) but velocity times 10 will not since his velocity is 0. etc...
If you continue moving player up and down in the gravity system you will always have peaks in the height, because player is actually facing opposite forces continuously(gravity vs your addforce) One thing I have in mind is to turn his rigidbody gravity field off (if it cannot be done just disable rigidbody on him) while you hold the button and after first iteration decrease the velocity or clamp it, well test it I cant say how it will work
Your answer
Follow this Question
Related Questions
How can i initiate an object in parabolic motion without using gravity using Rigidbody2D? 0 Answers
Rigidbody.velocity seems to be breaking jumping physics 0 Answers
Any way to gracefully detach object with Unity physics? 2 Answers
Problems with Physics(Flipping strangely) 2 Answers
How can i initiate an object in parabolic motion without using gravity using Rigidbody2D? 0 Answers