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 xthunderduckx · Dec 03, 2019 at 10:50 PM · movementphysics3dcharactercontroller

Why is my character controller moving in unrelated directions?

I tested my movement script with the following code (condensed for length), and without ever pressing "W" or "S," the player somehow manages to move forwards. I have also attached two images. In both images, the character controller's path is portrayed by a line renderer which follows the player. Additionally, in both cases the player only presses "A" and "D." In the second image, the player is rotated by exactly 54.609 degrees on the y axis. The difference being that when facing completely forwards, the issue where the player moves forward does not occur; why is the player moving forwards when pressing a/d as depicted in image 2?


I am attempting to avoid using transformDirection(velocity) on every characterController.Move() call, so that the player continues travelling in the same direction regardless of the rotation of the player, which is more or less the law of inertia.
alt text alt text

 if (Input.GetKey(KeyCode.W))
 {
     velocity += xzMover.transform.forward * accelerationSpeed * Time.deltaTime;
 }
 if (Input.GetKey(KeyCode.S))
 {
     velocity -= xzMover.transform.forward * accelerationSpeed * Time.deltaTime;
 }
 if (Input.GetKey(KeyCode.D))
 {
     velocity += xzMover.transform.right * accelerationSpeed * Time.deltaTime;
 }
 if (Input.GetKey(KeyCode.A))
 {
      velocity -= xzMover.transform.right * accelerationSpeed * Time.deltaTime;
 }
 playerController.move(velocity * Time.deltaTime);

Edit: Tested it with TransformDirection(x, 0, z), and got exactly the same results. For each keypresses, the velocity increased by transformDirection(accelerationSpeed, 0, accelerationSpeed), replacing either the x or the z with 0 depending on whether the player was increasing velocity on the x or z axis.

moveswrong.png (37.5 kB)
travelfine.png (95.0 kB)
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 Bunny83 · Dec 04, 2019 at 06:19 AM

I would simply assume that you move on a slope? So you naturally move down the slope due to the collision with the ground.

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 xthunderduckx · Dec 04, 2019 at 12:18 PM 0
Share

There is no slope.

avatar image Bunny83 xthunderduckx · Dec 04, 2019 at 01:23 PM 0
Share

Well, if that's not the case we have to know more about where else you modify your velocity. At the moment you only accelerate into the specified direction. If you don't have any kind of deceleration (drag, friction) once you have some velocity you won't get rid of it. If you actually implemented some kind of drag it depends on how you implemented it. Note that even it looks like you have stopped moving it doesn't mean you really stopped moving.


If the ground is not tilted, are you sure your character isn't as well? So it has 0 rotation on x and z but only on y? $$anonymous$$eep in $$anonymous$$d that the character controller can only rotate around y. Have you checked what values transform.forward and transform.right return? The y component should be 0,

avatar image xthunderduckx Bunny83 · Dec 04, 2019 at 02:42 PM 0
Share

I am not even rotating the character controller, actually. I use a child gameobject called "xz$$anonymous$$over" which only rotates on the y axis, in order to deter$$anonymous$$e the direction.

The transform of the general object never changes except position-wise; rotation stays the same.
I have actually disabled friction entirely for the moment, the only velocity changes are the player being constantly pushed into the ground by gravity, and what keys the player presses.

Show more comments

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

264 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 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 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

Can't fix slow jumping for character controller 3D 1 Answer

Objects stuck dragging across floor 1 Answer

How to let a GameObject generate force but not be affected by certain forces? 0 Answers

Crouching makes my player unable to move. 2 Answers

How to transform velocity to world space before calling controller.move? 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