- Home /
WallRun with a Jump
Hi there, I have a WallRun action. I would like to be able to Jump while Im wallrunning.
Right now my wallrun is just a translation in Z in the air.
My wallrun and my jump action input is left click.
Can anybody give me a hand.
Here is my script.
using UnityEngine;
using System.Collections;
public class WallRun : MonoBehaviour
{
public float wallRunningDistance;
public float climbingSpeed;
public AnimationCurve curve;
private CharacterController characterController;
private CharacterMotor motor;
private float originalHeight;
private Vector3 wallRunStartPosition;
private Vector3 destination;
private float currentTime = 0.0f;
private bool isWallRunning = false;
private bool leftClick = false;
private bool canWallRun = true;
private bool canJump = true;
void Start ()
{
characterController = GetComponent<CharacterController>();
motor = GetComponent<CharacterMotor>();
originalHeight = characterController.height;
}
void Update ()
{
if(canWallRun == true && characterController.isGrounded == false)
{
if(Input.GetMouseButtonDown(0))
{
canWallRun = false;
canJump = true;
characterController.center = new Vector3(0.0f, + originalHeight/2.0f, 0.0f);
wallRunStartPosition = transform.position;
destination.z = transform.position.z+ 1.0f;
destination = wallRunStartPosition + transform.forward * (wallRunningDistance + motor.movement.velocity.magnitude);
leftClick = true;
isWallRunning = true;
motor.canControl = false;
}
}
else if(characterController.isGrounded == true) // Peut seulement wallrunner une fois
{
canWallRun = true;
}
if(Input.GetMouseButtonUp(0)) // retrouve ma position original
{
leftClick = false;
}
if(isWallRunning)
{
if(currentTime < 1 )
{
currentTime += climbingSpeed * Time.deltaTime;
transform.position = Vector3.Lerp(wallRunStartPosition, destination , curve.Evaluate(currentTime));
}
if(!leftClick) // retrouve ma position original
{
canJump = true;
ResetWallRun();
}
}
}
private void ResetWallRun()
{
characterController.height = originalHeight;
characterController.center = new Vector3(0.0f, 0.0f, 0.0f);
currentTime = 0.0f;
isWallRunning = false;
motor.canControl = true;
}
}
Comment
Answer by Berenger · Mar 23, 2012 at 04:18 PM
If you know how to do a regular jump (there is one in FPSinputcontroller, or the TPS one), you just need to do the same whilst running, maybe adding the wal's normal in the direction.