Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by TristoWestside · Jan 16, 2017 at 12:56 AM · movementcontrollerdirectionjumpingcontrol

Air Control While Jumping?

so i'm trying to make a 3rd person platformer. everything works absolutely fine as it is. but what i want to be able to do is control the players direction while he is in the air/jumping. i have tried a lot of things so far and done a bit of research. i just cant seem to figure is out.. now i am only learning i an very new to coding. im just hoping that someone can push me in the right direction to get this to work. Thank-you!

     [Header("Speed/Movement Settings")]
     public float crouchSpeed = 2.5f;
     public float walkSpeed = 5f;
     public float runSpeed = 10f;
     public float maxSlopeLimit = 45f;
     private float speed; //the walk speed of the player
 
     [Header("Jumping/Gravity Settings")]
     public bool doubleJump; //bool for single of double jump
     public bool airMove;
     public float jumpForce = 15f; //how fast the player will move up when jumping
     public float gravity = 35f;    //how strong/fast gravity will pull you down
     public float airControl = 0.25f;
 
     [Header("Camera Settings")]
     public GameObject cam; //the camera used for the player. mainly here for the Up/Down look and Clamp.
     public float lookSensitivityX = 2f; // sets the sesitvity of the mouse Left/Right
     public float lookSensitivityY = 0.75f; // sets the sesitvity of the mouse Up/Down
     public float minLookY = -60f; //clamps the player look Down rotaion minimum
     public float maxLookY = 75f;    //clamps teh player look Up rotaton maximum
 
     Vector3 moveDir = Vector3.zero;
 
     int jumpTimes;    //how many times the player will be able to jump in the air
 
     float rotY;    //the rotaion of the camera UP/DOWN
     float rotX;    //the rotation of the camera LEFT/RIGHT
 
     void Update () // happens every frame
     {
         CharacterController controller = gameObject.GetComponent<CharacterController>(); // gets the character controller attached to the player.
 
         float ih =  Input.GetAxisRaw ("Horizontal"); // get the input of the horizontal axis (X)
         float iv = Input.GetAxisRaw ("Vertical");    // gets the input on the verticle axis (Z)
 
         if (controller.isGrounded) // if the player is on the ground
         { 
             if (Input.GetKey (KeyCode.LeftShift)) //if the Left Shift Key is Held Down Speed will = to Run Speed
             { 
                 speed = runSpeed;
                 controller.center = Vector3.zero;
             }
             else if (Input.GetKey (KeyCode.C)) // but if the C key is held down speed will = the couch speed
             { 
                 speed = crouchSpeed;
             } 
             else //if neither of the above keys are being held down speed will = to the defualt Walk speed
             { 
                 speed = walkSpeed;
                 controller.center = Vector3.zero;
             }
 
             moveDir = new Vector3 (ih, 0, iv).normalized; //seting where we want the axis to be modified and how
             moveDir = transform.rotation * moveDir.normalized; // allows the player to be able to rotate and the same speed he moves( i think haha ) 
             moveDir *= speed; // sets how fast the player will move
 
             jumpTimes = 0; // set jump time to 0 so you are able to jump again
 
         } 
 
         if (!doubleJump) //checks if the double jump bool is FALSE
         {
             //Debug.Log ("NormalJump");    // will show if single jump is active (in the console)
             JumpFunc ();    // find and moves through the single jump function
         }
 
         if (doubleJump) //checks if the double jump bool is TRUE
         {
             //Debug.Log ("DoubleJump");     // will show if double jump is active (in the console)
             DoubleJumpFunc ();    // find and moves through the double jump function
         }
             
         moveDir.y -= gravity * Time.deltaTime;    // this will move the player downward at the speed on gravity.
 
         controller.Move(moveDir * Time.deltaTime);    // this will allow the player to actually be able to move.
         Debug.Log (speed); // will show the speed of the player (in the console)
 
         controller.slopeLimit = maxSlopeLimit;    // this will set the players slope limit to a specified ammount.
     }
 
     void LateUpdate() //happens every other frame?
     {
         rotX = Input.GetAxis ("Mouse X") * lookSensitivityX;        //Sets up the mouse to look left and right
         rotY -= Input.GetAxis ("Mouse Y") * lookSensitivityY;        //Sets up the mouse to look up and down
 
         rotY = Mathf.Clamp (rotY, minLookY, maxLookY);    //Clamps the up and down rotation
 
         transform.Rotate (0, rotX, 0);    //Allows you to look left and right
         cam.transform.localRotation = Quaternion.Euler(rotY, 0, 0);    //Allows you to look up and down (with boundries -- Clamp)
     }
         
     void JumpFunc()    //single jump function
     {
         if (jumpTimes < 1) //see if the amount of times you have jumped is below 1
         {
             if (Input.GetButtonDown ("Jump")) //see if the space bar has been pressed 
             {
                 moveDir.y = jumpForce;    // move you upwards ad the speed of "jump force"
                 jumpTimes += 1; // +'s 1 on to the jump time so then it will be 1 meaning youll be able to jump one more time which will then make jump time = 2 which is not lower then 2. will not be able to jump again till on the ground
             }
         }
     }
 
     void DoubleJumpFunc()    //double jump function
     {
         if (jumpTimes < 2) //see if the amount of times you have jumped is below 2
         {
             if (Input.GetButtonDown ("Jump")) //see if the space bar has been pressed 
             {
                 moveDir.y = jumpForce;    // move you upwards ad the speed of "jump force"
                 jumpTimes += 1; // +'s 1 on to the jump time so then it will be 1 meaning youll be able to jump one more time which will then make jump time = 2 which is not lower then 2. will not be able to jump again till on the ground
             }
         }
     }
 }

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

Answer by TheyLeftMe4Dead · Jan 16, 2017 at 04:50 AM

The simple answer to your question is to have a separate function be called every frame (via Unity's built-in Update function). This function would allow the user to move left/right independent of jumping. From what I understand, right now you check if the user has pressed the left/right key after/before the jumping script runs. You need to constantly check if the user has pressed the left/right key rather than waiting until your jump happens.

Comment
Add comment · 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

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

105 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Animations are not playing with certain directions? 1 Answer

Top Down Character - Face direction of movement? 0 Answers

No Gravity Jump 0 Answers

Control Air movement with character controller 0 Answers

Bugs on move in air(falling); 0 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