[2D] Velocity increases faster after large force is applied.
Hello, I'm working on a small project where a ball can either jump or roll. Basically when the user holds the left mouse button I call the Rigidbody2D.addForce()
function with a really small value on the x to slowly increase the velocity until it gets to the max (10). Here's a small part of the Update()
function where I decide how much force I'm going to add:
if(rb.position.x < point2.x)
{
moveVelocity = new Vector2(0.1f, 0);
}
else
{
moveVelocity = new Vector2(-0.1f, 0);
}
And then the FixedUpdate()
function:
if(!jumping)
{
rb.AddForce(moveVelocity, ForceMode2D.Impulse);
}
By using the code above the ball gets to the mavelocity in around 5 seconds. As I said, the ball can also jump and it does that when the user drags the mouse while holding the left button. The force on the jump is calculated by the distance covered by the mouse, here's part of the code that does that:
var forcey = (mouseClickPosition.y - Input.mousePosition.y) / 25;
var forcex = (mouseClickPosition.x - Input.mousePosition.x) / 25;
jumpVelocity = new Vector2(forcex, forcey);
Like before, the jumpVelocity
vector will be used as the arg in a Rigidbody2D.addForce()
call in the FixedUpdate()
function.
To slowly decrease the velocity after a jump or a roll I'm using the same code as when calculating the force for the rolls but with swapped values and with a stop when the velocity gets to 0.
The code above works fine until the user actually jumps. After the landing both the decrease in velocity and the increase to 10 when rolling are instantaneous. I have no Idea why this is happening. I would really appreciate if you could point me in the right direction. Thanks.
Your answer
Follow this Question
Related Questions
Adding velocity to an object in a brick breaker game 0 Answers
dash till puff game 0 Answers
Stop drag on ball rolling down hill 0 Answers
Keep getting Error CS0131 1 Answer