Guys, I have constant movement in the X axis and when jump key is pressed there is an AddForce that adds force to the Y axis, but how can I add force also in the X axis so the jump feels more natural?
I can’t do it right now because o my velocity set is overriding the X addForce.
Here is my movement code:
void FixedUpdate()
{
rigidbody.velocity = new Vector3(speed.initialSpeed, rigidbody.velocity.y, 0);
if(!onGround)
{
this.rigidbody.AddForce(new Vector3(0,-gravity,0));
}
if(jump)
{
rigidbody.velocity = new Vector3(rigidbody.velocity.x, 0, 0);
rigidbody.AddForce(jumpForce, ForceMode.VelocityChange);
jump = false;
}
}
Thanks!