Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by IKilledKenny_2 · Feb 27, 2015 at 06:32 PM · javascriptcharactercharactercontrollerjump

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




Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image IKilledKenny_2 · Mar 02, 2015 at 05:41 PM 0
Share

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

avatar image hexagonius · Mar 02, 2015 at 05:51 PM 0
Share

Either the gravity value is too high, or jump/djump are negative (don't know how a serialized variable in UnityScript looks like).

avatar image IKilledKenny_2 · Mar 09, 2015 at 08:59 PM 0
Share

Sorry if this is late...I got it now.you was right,It was the gravity.

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges