- Home /
Double Jump Problem
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);
}
Answer by hexagonius · Feb 27, 2015 at 07:31 PM
According to the docs (sadly only under the explanation of SimpleMove):
http://docs.unity3d.com/ScriptReference/CharacterController.SimpleMove.html
It's recommended to only call Move or SimpleMove once per frame.
My guess is, that your movement script is overriding the move command from the doublejump script. I think you can test this by setting the script execution order on those two to see if one takes precedence over the other. Put the vectors together and calculate just one Vector3 for one call to Move.
Sorry if this is late...I think i got it=D! But now,$$anonymous$$y character drops to the floor.Does it has something to do with my gravity?
Double Jump
#pragma strict
var JumpSpeed : 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.Get$$anonymous$$eyDown ("space"))
{
velocity *= dJumpV;
velocity.y = dJump;
canDJump = false;
animation.Play("Jump");
}
if (controller.isGrounded)
{
velocity *= JumpSpeed;
if (Input.Get$$anonymous$$eyDown ("space"))
{
velocity.y = jump;
canDJump = true;
animation.Play("Jump");
}
}
velocity.y -= gravity * Time.deltaTime;
controller.$$anonymous$$ove (velocity * Time.deltaTime);
}
$$anonymous$$ovement
Either the gravity value is too high, or jump/djump are negative (don't know how a serialized variable in UnityScript looks like).
Sorry if this is late...I got it now.you was right,It was the gravity.
Your answer
Follow this Question
Related Questions
How to fix a infinity jump? 1 Answer
Custom Character Script Allowing Movement in the Air? 0 Answers
Character Controller sticky head.... Help!? 1 Answer
Translation of an object 2 Answers
How do I fix my player jumping code? 2 Answers