Hello Unity3D.I have a problem with making my character double jump.The problem is when i use my character movement script.The character moves and my double jump scrip,The character moves.But,The character doesn’t double jump.But when i take off the character movement script.The character double jumps but the character doesn’t.Does anyone know why my character movement script doesn’t make my character double jump unless i remove the movement script from the character?If anyone knows why?Can you please tell me
Movement script
var walkSpeed : float = 7;
var body : Transform;
audio.volume = 0;
private var yRot: float;
function Update () {
var Controller : CharacterController = GetComponent(CharacterController);
var vertical : Vector3 = transform.TransformDirection(Vector3.forward);
var horizontal : Vector3 = transform.TransformDirection(Vector3.right);
var horizontal2: Vector3 = transform.TransformDirection(Vector3.left);
if(Input.GetAxis("Vertical")||Input.GetAxis("Horizontal")){
if (!animation.IsPlaying("Jump"))
if (!animation.IsPlaying("Jump"))
if(!animation.IsPlaying("Kick1"))
if(!animation.IsPlaying("Sword_5"))
if(!animation.IsPlaying("Sword_6"))
if(!animation.IsPlaying("Sword_7"))
if(!animation.IsPlaying("Sword_8"))
if(!animation.IsPlaying("Spinning_Slashes"))
animation.CrossFade("Run2");
animation["Run2"].speed = walkSpeed/100;
Controller.Move((vertical * (walkSpeed * Input.GetAxis("Vertical"))) * Time.deltaTime);
Controller.Move((horizontal * (walkSpeed * Input.GetAxis("Horizontal"))) * Time.deltaTime);
audio.Play();
}else{
if (!animation.IsPlaying("Jump"))
if(!animation.IsPlaying("Assassin_s_Greeting_Part_5"))
if(!animation.IsPlaying("Assassin_s_Greeting_Part_6"))
if(!animation.IsPlaying("Overhead_slash4"))
if(!animation.IsPlaying("Overhead_slash3"))
if(!animation.IsPlaying("Violets_Pause_2"))
if(!animation.IsPlaying("Assassin_s_Greeting_Part_1"))
if(!animation.IsPlaying("Assassin_s_Greeting_Part_2"))
if(!animation.IsPlaying("Assassin_s_Greeting_Part_3"))
if(!animation.IsPlaying("Assassin_s_Greeting_Part_4"))
if(!animation.IsPlaying("punch1"))
if(!animation.IsPlaying("punch2"))
if(!animation.IsPlaying("punch3"))
if(!animation.IsPlaying("punch4"))
if(!animation.IsPlaying("punch5"))
if(!animation.IsPlaying("Berserk"))
if(!animation.IsPlaying("Teleport"))
if(!animation.IsPlaying("Snake_"))
if(!animation.IsPlaying("Snake__2"))
if(!animation.IsPlaying("Snake__3"))
if(!animation.IsPlaying("Snake__4"))
if(!animation.IsPlaying("Snake__Launcher"))
if(!animation.IsPlaying("Juggle_Launcher_Ground"))
if(!animation.IsPlaying("invisibility"))
if(!animation.IsPlaying("Violets_Mine_Throw"))
if(!animation.IsPlaying("Demonic_Wave"))
if(!animation.IsPlaying("Slash_Combo"))
if(!animation.IsPlaying("Slash_Combo_2"))
if(!animation.IsPlaying("Rex_Pause"))
if(!animation.IsPlaying("Escalibur"))
if(!animation.IsPlaying("Invisibility"))
if(!animation.IsPlaying("Machete_Finisher_3"))
if(!animation.IsPlaying("Machete_Finisher_2"))
if(!animation.IsPlaying("Machete_Finisher"))
if(!animation.IsPlaying("Triple_Snake_Punch"))
if(!animation.IsPlaying("Triple_Gunt"))
if(!animation.IsPlaying("Double_Palm"))
if(!animation.IsPlaying("Falling_Axe_Kick"))
if(!animation.IsPlaying("Triple_Gunt"))
if(!animation.IsPlaying("Sweep_Kick"))
animation.CrossFade("Violets_Stance");
audio.Play();
}
}
function LateUpdate(){
// Rotate the Character to match the direction he/she is going
if(Input.GetAxis("Vertical") == 0){
if(Input.GetAxis("Horizontal") > 0){
body.localEulerAngles.y = 90;//Right sideways running
}else if(Input.GetAxis("Horizontal") < 0){
body.localEulerAngles.y = 270;//Left sideways running
}
}else if(Input.GetAxis("Vertical") > 0){
if(Input.GetAxis("Horizontal") > 0){
body.localEulerAngles.y = -270;
}else if(Input.GetAxis("Horizontal") < 0){
body.localEulerAngles.y = -90;
}
}else if(Input.GetAxis("Vertical") < 0){
if(Input.GetAxis("Horizontal") == 0){
body.localEulerAngles.y = -180;
}else if(Input.GetAxis("Horizontal") > 0){
body.localEulerAngles.y = -180;
}else if(Input.GetAxis("Horizontal") < 0){
body.localEulerAngles.y = -180;
}
}
}
Double Jump Script
#pragma strict
var speed : float = 4.0;
var jump : float = 10.0;
var dJump : float = 10.0;
var gravity : float = 20.0;
var dJumpV : float = 4.0;
private var canDJump : boolean = false;
private var velocity : Vector3 = Vector3.zero;
var controller : CharacterController;
function Update() {
if (!controller.isGrounded && canDJump && Input.GetKeyDown ("space"))
{
velocity = GetHorizontalMovementDirection();
velocity *= dJumpV;
velocity.y = dJump;
canDJump = false;
}
if (controller.isGrounded)
{
velocity = GetHorizontalMovementDirection();
velocity *= speed;
if (Input.GetKeyDown ("space"))
{
velocity.y = jump;
canDJump = true;
}
}
velocity.y -= gravity * Time.deltaTime;
controller.Move (velocity * Time.deltaTime);
}
function GetHorizontalMovementDirection() {
var direction : Vector3 = Vector3 (Input.GetAxisRaw ("Horizontal"), 0, 0);
return transform.TransformDirection (direction);
}