x


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;
}      

}

more ▼

asked Mar 27 '12 at 01:04 PM

Toy gravatar image

Toy
35 15 29 35

(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x336
x111
x101
x15
x10

asked: Mar 27 '12 at 01:04 PM

Seen: 521 times

Last Updated: Mar 27 '12 at 01:04 PM