• 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 ziC · Jun 25, 2011 at 05:38 PM · move

charactercontroller.move() dont work right

 var speed : float = 6.0;
 var jumpSpeed : float = 8.0;
 var gravity : float = 20.0;
 
 private var moveDirection : Vector3 = Vector3.zero;
 
 function Update() {
 var controller : CharacterController = GetComponent(CharacterController);
 if (controller.isGrounded) {
 // We are grounded, so recalculate
 // move direction directly from axes
 moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,
 Input.GetAxis("Vertical"));
 moveDirection = transform.TransformDirection(moveDirection);
 moveDirection *= speed;
 
 if (Input.GetButton ("Jump")) {
 moveDirection.y = jumpSpeed;
 }
 }
 
 // Apply gravity
 moveDirection.y -= gravity * Time.deltaTime;
 
 // Move the controller
 controller.Move(moveDirection * Time.deltaTime);
 }

This code dont work as i should for me, the positive vertical value dont work right. Anyone had the same problem?

This code is direct from the unity script reference manual.

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 testure · Jun 25, 2011 at 05:52 PM 0
Share

have you verified that moveDirection.y is not zero? in other words- is your jump button event even being called?

avatar image ziC · Jun 25, 2011 at 06:01 PM 0
Share

yes the values is all correct but the controller.move some how mess them up. values are -2.0 - 2.0 for x,y and z when buttons are pressed

2 Replies

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

Answer by ziC · Jun 26, 2011 at 09:08 AM

This is solved, this code is corrent! Problem was i parented in stuff with the character that had colliders ._.

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

Answer by kronicles · Jun 25, 2011 at 06:17 PM

 var speed : float = 7.0;
 var jumpSpeed : float = 4.0;
 var gravity : float = 5.0;
 var rotateSpeed : float = 3.0;
 
 private var moveDirection : Vector3 = Vector3.zero;
 
 function Update() {
 var controller : CharacterController = GetComponent(CharacterController);
 
 transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
 
 if (controller.isGrounded) {
 
 moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,
 Input.GetAxis("Vertical"));
 moveDirection = transform.TransformDirection(moveDirection);
 moveDirection *= speed;
 
 if (Input.GetButton ("Jump")) {
 moveDirection.y = jumpSpeed;
 }
 }
 
 moveDirection.y -= gravity * Time.deltaTime;
 
 controller.Move(moveDirection * Time.deltaTime);
 }
 
 @script RequireComponent(CharacterController)

The character doesn't move or the character moves in strange ways?

Make sure that you don't have any joystick turned on the computer!

Make sure that you applied the script on the character! XD (Sometimes happens to me)

And tag the character as a player too :P

Comment
Add comment · Show 1 · 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 ziC · Jun 25, 2011 at 06:38 PM 0
Share

The character dont move forward, but the other directions work. i have no joystick, script is applied, taged it player(did nothing)

I really have no idea here..

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How do I make the nose/whole of my spaceship move? 2 Answers

Make Objects to ricochet 1 Answer

How Can I Make The Parkour Moves Move Smoothly Instead Of Instantly Teleport? 1 Answer

Gui problems. 1 Answer

Mecanim walk to target position 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