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
1
Question by Elringus · Oct 05, 2012 at 10:22 PM · charactercontrollervelocity

CharacterController velocity problem

Hi,

I have a problem registering CharacterController X and Z velocities – they always stays at 0.

This is my script attached to the character:

 using UnityEngine;
 using System.Collections;
 
 [RequireComponent(typeof(CharacterController))]
 [RequireComponent(typeof(Animation))]
 
 public class scr_controller : MonoBehaviour {
     
     private CharacterController controller;
     private Animation animations;
 
     void Awake() {
         controller = GetComponent<CharacterController>();
         animations = GetComponent<Animation>();
     }
     
     void Update () {
         if (Input.GetAxis("Horizontal") > 0) transform.Rotate(0,100 * Time.deltaTime,0);
         if (Input.GetAxis("Horizontal") < 0) transform.Rotate(0,-100 * Time.deltaTime,0);
         if (Input.GetAxis("Vertical") > 0) controller.Move(transform.TransformDirection(Vector3.forward) * Time.deltaTime * 3);
         if (Input.GetAxis("Vertical") < 0) controller.Move(transform.TransformDirection(Vector3.back) * Time.deltaTime * 3);
         
         controller.Move(Vector3.down * Time.deltaTime * 9.8f);
         
         if (controller.velocity.magnitude == 0) animations.CrossFade("idle");
         else animations.CrossFade("walk");
         
         print(controller.velocity);
     }
 }

So, when I move him, controller.velocity keeps returning a zero vector. However, if my characters falls from somewhere Y velocity seems to react appropriately.

I’m really confused with that problem. Would appreciate any help. Thanks!

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 MountDoomTeam · Nov 18, 2012 at 09:19 AM

it looks like you're calling the velocity on a component called charactercontroller, and you have to call it the object the charactercontroller is attached to.the velocity function has to be on a rigid body. So print(GameObject.rigidbody.velocity), something like that

Comment
Add comment · Show 2 · 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 Elringus · Nov 18, 2012 at 09:55 AM 0
Share

But I don't use a rigidbody component there... The say (http://docs.unity3d.com/Documentation/ScriptReference/CharacterController-velocity.html) that it should return "the difference in distance for the current timestep before and after a call to CharacterController.$$anonymous$$ove or CharacterController.Simple$$anonymous$$ove".

avatar image chinanzio · Dec 31, 2012 at 03:52 PM 0
Share

controller.$$anonymous$$ove(Vector3.down Time.deltaTime 9.8f);

that line only moves over Y axis, and it seems that you are reseting previous calls to $$anonymous$$ove

... if (Input.GetAxis("Vertical") > 0) controller.$$anonymous$$ove(transform.TransformDirection(Vector3.forward) Time.deltaTime 3); if (Input.GetAxis("Vertical") < 0) controller.$$anonymous$$ove(transform.TransformDirection(Vector3.back) Time.deltaTime 3); ...

Create only one movement vector and call $$anonymous$$ove one time per update

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

11 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

Related Questions

i am getting velocity when ever my player with character controller collides with a Enemy With character controller.kindly suggest me solutions. 0 Answers

CharacterController causing characters to fly around screen 1 Answer

How to stop CharacterController during Collider's moving? 0 Answers

Removing velocity relative to the contact normal 1 Answer

How to get local axis from characterController.velocity 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