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 /
avatar image
0
Question by tiyyargee · Jan 02, 2017 at 11:41 AM · c#script.charactercontrollerjumpjumping

can anyone help me to smooth the jump?

hello guys i need a little help i have a player jump correctly when i'm not moving ..but when i'm running if i press the space bar and release it when my player is in air , i noticed that the player makes a double charged jump and i don't want that, i want to make single jump using UnityEngine; using System.Collections;

public class player_motion123 : MonoBehaviour {

 public Animator anim;
 //public Transform center_point;
 public Quaternion newrotation;
 public float smooth = 0.05f;


 public float speed;
 public CharacterController controller;
 public static bool ismoving=false;
 public static bool isRunning=false;

 public Transform cam;
 bool grounded;

 // jump


 private float verticalVelocity;
 public float gravity;
 public float JumpForce;
 public float JumpForce2;
 public bool jumping;







 void Start()
 {
     
 }




 void Update ()
 {
     
     float v = Input.GetAxis ("Vertical");

     float h = Input.GetAxis ("Horizontal");

     if (player_Sword_Attack.attacking == false) 
     {
         Move (h, v);
         Run (h, v);
         jump ();

     }



 }



 void Move(float h ,float v)

 {
     
     if (h != 0f || v != 0f)
     {
         
         rotate (v, h);
         controller.SimpleMove (transform.forward * speed);
         anim.SetFloat ("Speed", 0.5f);
         ismoving = true;
     } else {
         anim.SetFloat ("Speed",0);
         ismoving = false;
     }

 }


 void Run(float h, float v)
 {
     if (ismoving && Input.GetKey (KeyCode.LeftShift)) {

         rotate (v, h);
         controller.SimpleMove (transform.forward * speed * 2);
         anim.SetFloat ("Speed", 1);
         isRunning = true;
     }
     else if (ismoving && Input.GetKeyUp (KeyCode.LeftShift)) {
         anim.SetFloat ("Speed", 0.5f);
         isRunning = false;
     }
     else if (!ismoving && Input.GetKeyUp (KeyCode.LeftShift)) {
         anim.SetFloat ("Speed", 0);
         isRunning = false;
     }



 }




 void jump()
 {
     
     if (controller.isGrounded) 
     {
         verticalVelocity = -gravity * Time.deltaTime;
         anim.SetBool ("Jumping",false);
         if (Input.GetKeyDown (KeyCode.Space)) 
         {
             verticalVelocity = JumpForce;
             jumping = true;
             if (isRunning)
             verticalVelocity = JumpForce2;
             
             jumping = true;

         }
     }
     else 
     {
         
         verticalVelocity -= gravity * Time.deltaTime;
         if(Input.GetKeyUp(KeyCode.Space))
         anim.SetBool ("Jumping",true);
         jumping = false;

     }
     Vector3 moveVector = Vector3.zero;
     moveVector.x = Input.GetAxis ("Horizontal");
     moveVector.y = verticalVelocity;
     moveVector.z = Input.GetAxis("Vertical")*5.0f;
     controller.Move (moveVector*Time.deltaTime);




 }







 void rotate(float v,float h) {
     if (v > 0)
     {
         if (h > 0)
         {
             newrotation = Quaternion.Euler(0,cam.eulerAngles.y+45,0);
         }
         else if (h < 0)
         {
             newrotation = Quaternion.Euler(0,cam.eulerAngles.y+305,0);
         }
         else
         {
             newrotation = Quaternion.Euler(0,cam.eulerAngles.y,0);
         }
     }
     else if (v < 0)
     {
         if (h > 0)
         {
             newrotation = Quaternion.Euler(0,cam.eulerAngles.y+135,0);
         }
         else if (h < 0)
         {
             newrotation = Quaternion.Euler(0,cam.eulerAngles.y+225,0);
         }
         else {
             newrotation = Quaternion.Euler(0,cam.eulerAngles.y+180,0);
         }
     }
     else
     {
         if (h > 0)
         {
             newrotation = Quaternion.Euler(0,cam.eulerAngles.y+90,0);
         }
         else if (h < 0)
         {
             newrotation = Quaternion.Euler(0,cam.eulerAngles.y+270,0);
         }
         else {
             newrotation = transform.rotation;
         }
     }


     newrotation.x = 0;

     newrotation.z = 0;

     //We only want player to rotate in y axis
     transform.rotation = Quaternion.Slerp (transform.rotation,newrotation, smooth);

     //Slerp from player's current rotation to the new intended rotaion smoothly 
 }


}

Comment
Add comment · Show 2
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 arain55 · Jan 02, 2017 at 01:53 PM 0
Share

I tested the script and it works fine?

avatar image tiyyargee arain55 · Jan 03, 2017 at 02:07 PM 0
Share

if i'm running and i jump and still press the W key it works fine,,,, but try it when running and jump and quickly remove your hand from W and shiftkey when the player is in the air it will make double jump

0 Replies

· Add your reply
  • Sort: 

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

8 People are following this question.

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

Related Questions

jump with character controller best way? 1 Answer

How do I make this jump function work? 1 Answer

Not able to jump 1 Answer

Can't figure out how to detect ground (2D) 1 Answer

Using isGrounded with a RigidBody 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