- Home /
Why isn't my player looking the other direction when I wall jump (please help I am desperate)
void Update()
{
if (!CanMoveOrInteract())
{
horizontalValue = 0;
return;
}
//Store the horizontal value
horizontalValue = Input.GetAxisRaw("Horizontal");
//If LShift is clicked enable isRunning
if (Input.GetKeyDown(KeyCode.LeftShift))
isRunning = true;
//If LShift is released disable isRunning
if (Input.GetKeyUp(KeyCode.LeftShift))
isRunning = false;
//If we press Jump button enable jump
if (Input.GetButtonDown("Jump"))
Jump();
//If we press Crouch button enable crouch
if (Input.GetButtonDown("Crouch"))
isCrouching = true;
//Otherwise disable it
else if (Input.GetButtonUp("Crouch"))
isCrouching = false;
if (Input.GetKeyDown(KeyCode.Return))
animator.SetBool("Shoot", true);
else if (Input.GetKeyUp(KeyCode.Return))
animator.SetBool("Shoot", false);
//Set the yVelocity Value
animator.SetFloat("yVelocity", rb2d.velocity.y);
//Check if we are touching a wall to slide on it
WallCheck();
}
void WallCheck()
{
//If we are a touching a wall
//and we are moving towards the wall
//and we are falling
//and we are not grounded
//Slide on the wall
if (Physics2D.OverlapCircle(wallCheckCollider.position, wallCheckRadius, wallLayer)
&& Mathf.Abs(horizontalValue) > 0
&& rb2d.velocity.y < 0
&& !isGrounded)
{
if (!isSliding)
{
availableJumps = totalJumps;
multipleJumps = false;
}
Vector2 v = rb2d.velocity;
v.y = -slideFactor;
rb2d.velocity = v;
isSliding = true;
if (Input.GetButtonDown("Jump"))
{
availableJumps--;
rb2d.velocity = new Vector2(-horizontalValue * jumpPower, jumpPower);
AudioManager.instance.PlaySFX("jump");
animator.SetBool("Jump", true);
}
}
else
{
isSliding = false;
}
}
@TheSOULDev
if (Input.GetButtonDown("Jump"))
{
availableJumps--;
rb2d.velocity = new Vector2(-horizontalValue * jumpPower, jumpPower);
AudioManager.instance.PlaySFX("jump");
animator.SetBool("Jump", true);
}
This is the part where you perform the walljump right? Maybe I'm missing out on something here, but you are not rotating anything in that script as far as I can tell. So that's why your player isn't looking in the opposite direction when you perform a wall jump :D
Also, though this has nothing to do with the question, it might be of interest to you that you can make your input a bit cleaner by just using Input.GetKey() or Input.GetButton() instead of the GetButtonDown() And GetButtonUp() methods :D
Ok, I flipped the character but is not getting the effect I want, like I want my character to be unable to move and jump the other direction (lets say for .5 sec) when jumping off of a wall. I cannot understand what I have done wrong in my code.. (I'm a beginner)
Ok, so the game (I'm guessing) is sort of a Platformer right? So flipping the character in 2D space is simple: transform.Rotate(new Vector3(0, 180f));
this flips the character sprites in the opposite direction. The 'not moving' part when jumping should be easily achieved by having a bool, which sets to true if the player jumps off the wall and false when he is grounded again, or after a certain time by making a float countdown;
then you add Time.deltaTime every Update onto the countdown and when you jump set it to 0, that way you can track how much time has gone by since the player jumped off the wall :D
Answer by thereadypunk · Apr 23, 2021 at 04:12 PM
@Imalilpie When performing the wall kick, simply set transform.localscale.x = -transform.localscale.x; and then set it back to normal when the wall kick is done :)