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 Covenant · Feb 13, 2014 at 10:36 PM · charactercontrollercharacter.move

Using .move(), the enemy moves faster at a diagonal

Considering:

 direction = _player.position - transform.position;
 direction.y = 0;
 direction = Vector3.Normalize(direction);
 velocity = direction * _moveSpeed * Time.deltaTime;


Why does the enemy have variable speed at different angles when using:

 _controller.Move(velocity);


While the enemy has constant speed no matter the direction using:

 _controller.transform.position += velocity;

I'd prefer to use the .Move function but what is going on in it? Why isn't the speed constant?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Maui-M · Feb 13, 2014 at 10:47 PM

Normalize scales all the values down so the max value is one. So if x=1 and z=1 you would essentially be moving at a speed of 1.4(square root of 2) instead of 1 in the x or z direction.

Try using:

 transform.TransformDirection(direction);

Instead of:

 direction = Vector3.Normalize(direction);

Character Controller

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 Ultroman · Nov 13, 2017 at 08:02 PM

Since normalizing the movement vector results in a movement vector that is always 1 in length, you lose the granularity/interpolation functionality of an analog stick, so I would like to refer to the following Unity forum post: https://forum.unity.com/threads/diagonal-movement-speed-to-fast.271703/

...where I found the solution to my similar problem, when using the analog stick on my controller.


Quote from cranky:

Normalizing [the movement vector] isn't always the best solution. If you're using a keyboard, it's fine. But with an analog stick, it will always force the length of the vector to be 1, so you won't be able to move slowly. Instead, get the length of the vector and see if it's greater than 1. If so, divide the movement vector by the length.


...and also (quoting myself)...

Make sure the "Sensitivity" of your analog stick axes is set to no more than 1! Mine were set to 2 for some reason (damn copy/pasting from old projects), so even when using cranky's fix, I had inputs of (1f, 1f) when within ~30 degrees of either diagonal, while holding the stick to its extremity. This made me think there might be some input-multiplier...and voila, sensitivity was the culprit.

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 IntergalacticSloth · May 18, 2018 at 06:44 AM 0
Share

I'm not sure that's the solution either. Or maybe I'm confused.

The solution seems to always work when travelling straight.

The solution works when travelling at a diagonal at FULL FORC$$anonymous$$

But travelling at, say, HALF force at a diagonal causes problems. Even using $$anonymous$$agnitude or Sqr$$anonymous$$agnitude I think I am seeing this problem... If the player intends to go half force at an angle, I'm having trouble getting a simple "if" statement to catch that. So I'm still losing granularity at angles.

Unless I'm confused?? I drew a picture where half forces are shown in RED

https://imgur.com/a/JaDAZL1

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

21 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

Related Questions

Pushing a character controller (physics interaction) 0 Answers

why does character controller accelerate off ledges? 1 Answer

How to combine Quaternions? 1 Answer

(CharacterController) Jumping from other script 0 Answers

CharacterController movement messed up when Y Center is larger than radius 0 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