2D Wall Jump Script Help
void Update() { if (wallSliding && !player.grounded) { gameObject.GetComponent().velocity = new Vector2(gameObject.GetComponent().velocity.x, -slideSpeed); }
if(Input.GetKeyDown(KeyCode.Space) && wallSliding)
{
if (player.lastVelocityX > 0)
{
gameObject.GetComponent<Rigidbody2D>().velocity = new Vector2(-jumpLength, jumpHeight);
}
else if (player.lastVelocityX < 0)
{
gameObject.GetComponent<Rigidbody2D>().velocity = new Vector2(jumpLength, jumpHeight);
}
}
}
When the player performs a wall jump he sort of teleports to the side first and then moves straight up before falling back down. If anyone can see why or maybe have a better method of doing this, it would be greatly appreciated.
Answer by andrei2699 · May 13, 2016 at 04:08 AM
You change the velocity of the object. Try applying a force to it instead. For example, you multiply the jumping axis with the power of jumping.
gameObject.GetComponent<Rigidbody2D>().AddForce(transform.up * jumpPower);
Rigidbody.AddForce Documentation.
Your answer
Follow this Question
Related Questions
How to move upward with wall jump and not be pulled down too quickly? 0 Answers
Can do wall jump 0 Answers
2D Plataformer: Character doesn't Flip after Walljump . C# 1 Answer
Changing Color 1 Answer