- Home /
Question by
vlakitus · Oct 22, 2018 at 01:33 PM ·
unity 2daddforceplatformerwall jump
Problem with Wall Jump - 2D
Hey Guy! I'm stuck
When the player performs a wall jump he sort of teleports to the side first and then moves straight up before falling back down.
Here is the method wallJump();
void wallJump(){
if (horizontalNumber > 0 && !faceLeft)
{
flipCharacter();
// playerRb.velocity = (new Vector2(-horizontalNumber * wallJumpClimb.x * 50f, wallJumpClimb.y));
// playerRb.velocity = Vector2.left * jumpForceCharacter * -wallJumpClimb.x;
playerRb.AddForce(new Vector2(-horizontalNumber * wallJumpClimb.x * 5f, wallJumpClimb.y));
print("Pulei da direita");
}
else if (horizontalNumber < 0 && faceLeft)
{
flipCharacter();
playerRb.velocity = (new Vector2(horizontalNumber * wallJumpClimb.x * 5f, wallJumpClimb.y));
print("Pulei da esquerda");
}
isJumping = true;
jumpTimeCounter = jumpTime;
if (extraJumps < 0)
{
extraJumps = 0;
}
float gravity = -(2 * 3.5f) / Mathf.Pow(0.4f, 2);
playerRb.velocity = (new Vector2(gravity * Time.deltaTime, gravity * Time.deltaTime));
}
Here is the conditional to wallJump method:
if (Input.GetButtonDown("Jump") && !grounded && !attacking && isWall)
{
wallJump();
}
Both are on Update method.
In my FixedUpdate i have this:
private void FixedUpdate()
{
grounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsGround);
isWall = Physics2D.OverlapCircle(wallCheck.position, checkRadius, whatIsWall);
horizontalNumber = Input.GetAxisRaw("Horizontal");
verticalNumber = Input.GetAxisRaw("Vertical");
if(!isWall)
{
playerRb.velocity = new Vector2(horizontalNumber * speedCharacter, playerRb.velocity.y);
}
interact();
}
I'm new in unity and don't see what's wrong. If anyone can see why or maybe have a better method of doing this, it would be greatly appreciated.
The Result og this code: https://imgur.com/a/JUiFA56
Comment