- Home /
Jump with a wallrun
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. How can I script a jump while im wallrunning ?
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
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
WallRun with a Jump 2 Answers
Making a "vault over an obstacle" script 0 Answers
How do I script so my character Jumps farther when Running? 1 Answer