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 /
avatar image
0
Question by Hektor · Jan 20, 2011 at 02:29 PM · charactercontrollerjump

How to jump with the Character Controller

Hello everyone, I'm trying to make a Character Controller to jump, but it doesn't works properly. This is my script:

var speed : float = 3.0; var gravity : float = 20.0; var rotateSpeed : float = 3.0; var jumpSpeed : float = 8.0; private var moveDirection : Vector3 = Vector3.zero;

function Update () { var controller : CharacterController = GetComponent(CharacterController); if(controller.isGrounded){
transform.Rotate(0,0,Input.GetAxis ("Horizontal") * rotateSpeed);

transform.Rotate(0,0,Input.GetAxis ("Unhorizontal") * -rotateSpeed);

var forward : Vector3 = transform.TransformDirection(Vector3.left); var curSpeed : float = speed * Input.GetAxis ("Vertical");

if (Input.GetButton ("Jump")) {transform.Translate(Vector3.forward jumpSpeed Time.deltaTime);}

}

moveDirection.y -= gravity Time.deltaTime; controller.SimpleMove(forward curSpeed);

}

@script RequireComponent(CharacterController)

Can you explain me the proper way to do it please?

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
3
Best Answer

Answer by superventure · Jan 20, 2011 at 08:41 PM

You forgot 'controller.Move(moveDirection * Time.deltaTime);' to the bottom where you have the simple.move line.

try this

var speed : float = 3.0; var gravity : float = 20.0; var rotateSpeed : float = 3.0; var jumpSpeed : float = 8.0; private var moveDirection : Vector3 = Vector3.zero;

function Update () { var controller : CharacterController = GetComponent(CharacterController); var forward : Vector3 = transform.TransformDirection(Vector3.left); var curSpeed : float = speed Input.GetAxis ("Vertical");transform.Rotate(0,0,Input.GetAxis ("Horizontal") rotateSpeed);

transform.Rotate(0,0,Input.GetAxis ("Unhorizontal") * -rotateSpeed);

controller.SimpleMove(forward * curSpeed);

if (Input.GetButton ("Jump")) if(controller.isGrounded){ moveDirection.y= jumpSpeed;

}

moveDirection.y -= gravity * Time.deltaTime;

controller.Move(moveDirection * Time.deltaTime); }

Comment
Add comment · Show 5 · 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 Hektor · Jan 21, 2011 at 01:14 PM 0
Share

Thank's for your time! Now it works at all!

avatar image robotmaker01 · Aug 16, 2012 at 12:38 AM 0
Share

the code you given is not smooth only the falling is(its by charachter controller)this code just teleports the player to a higher position and let the character controller do the rest, any idea how to make it smooth?

avatar image sona.viswam · Nov 29, 2012 at 11:56 AM 0
Share

Nice code .It helped me...

avatar image Coreyf716 · Dec 17, 2012 at 02:01 AM 0
Share

You don't need to call the variable of controller every frame. Put it outside of update and assign it in the inspector for better performance.

avatar image Hala · May 23, 2013 at 09:14 AM 0
Share

This provided a great deal of help, thank you!

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

6 People are following this question.

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

Related Questions

Two near-identical scripts cause a cat to jump in different ways - why? 2 Answers

Character controller check ground while falling. 1 Answer

jump with character controller best way? 1 Answer

Jumping Stopped Working. 2 Answers

Character Controller Jump with FPS problem 1 Answer


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