Hi all! I need some help, I’m making a 2D Platformer Game, I have my own physics system set up from ray casts, my player can jump, run and grab onto a wall, at the moment he can also jump off of the wall but that requires the player to press in that direction.

What I want is to have the player jump backwards from the wall by itself in the opposite direction from the wall when the player presses the jump button again (and also play a different animation to the standard jump (i.e, a backflip)

Here is a section of my code that controls these parts, if you need the rest to sort it out I’ll gladly post that too:

``````void Update () {
// Reset acceleration upon collision
if (playerPhysics.movementStopped) {
targetSpeed = 0;
currentSpeed = 0;
}

// If player is touching the ground
if (playerPhysics.grounded) {
amountToMove.y = 0;

if (wallHolding) {
wallHolding = false;
animator.SetBool("Wall Hold", false);
}

// Jump logic
if (jumping) {
jumping = false;
animator.SetBool("Jumping",false);
}

// Slide logic
if (sliding) {
if (Mathf.Abs(currentSpeed) < .25f) {
sliding = false;
animator.SetBool("Sliding",false);
playerPhysics.ResetCollider();
}
}

// Slide Input
if (Input.GetKeyDown(KeyCode.DownArrow)) {
sliding = true;
animator.SetBool("Sliding",true);
targetSpeed = 0;

playerPhysics.SetCollider(new Vector3(10.3f,1.5f,3), new Vector3(.35f,.75f,0));
}
}
else {
if (!wallHolding) {
if (playerPhysics.canWallHold) {
wallHolding = true;
animator.SetBool("Wall Hold", true);
}
}
}

// Jump Input
if (Input.GetButtonDown("Jump")) {
if (playerPhysics.grounded || wallHolding) {
amountToMove.y = jumpHeight;
jumping = true;
animator.SetBool("Jumping",true);

if (wallHolding) {
wallHolding = false;
animator.SetBool("Wall Hold", false);
}
}

}
// Set animator parameters
animationSpeed = IncrementTowards(animationSpeed,Mathf.Abs(targetSpeed),acceleration);
animator.SetFloat("Speed",animationSpeed);

// Input
moveDirX = Input.GetAxisRaw("Horizontal");
if (!sliding) {
float speed = (Input.GetButton("Run"))?runSpeed:walkSpeed;
targetSpeed = moveDirX * speed;
currentSpeed = IncrementTowards(currentSpeed, targetSpeed,acceleration);

// Face Direction
if (moveDirX !=0  !wallHolding) {
transform.eulerAngles = (moveDirX>0)?Vector3.up * 180:Vector3.zero;
}
}
else {
currentSpeed = IncrementTowards(currentSpeed, targetSpeed,slideDeceleration);
}

// Set amount to move
amountToMove.x = currentSpeed;

if (wallHolding) {
amountToMove.x = 0;
if (Input.GetAxisRaw("Vertical") != -1) {
amountToMove.y = -2;
}
}

amountToMove.y -= gravity * Time.deltaTime;
playerPhysics.Move(amountToMove * Time.deltaTime, moveDirX);

}
``````