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
2
Question by Tseng · Dec 06, 2010 at 08:28 PM · movementspeedacceleration

Movement/Acceleration problems

Hello,

I have a problem with the movements of my object (in this particular case the Player character).

Short Version: Moving works fine so far, but when running diagonally, the character moves faster.

Long Version: I've scripted a Controller and Camera View for an isometric like game, like typical in older console RPGs. The Camera points in a fixed direction and moves with the character and can't be rotated (for now). The Character basically moves along the camera axis, so pressing W will always move the character in the direction of top of the screen, D will always move it to the right etc.

This works perfectly so fine. Well, almost. Problem is, when the character is moving diagonally, he moves faster. I already go an idea why it's so, however I haven't found a good solution yet to scale it down.

But take a look at the code below:

// Update is called once per frame void Update () { // update movement only when the character is grounded if(charController.isGrounded == true) { float horizontal = Input.GetAxis("Horizontal"); float vertical = Input.GetAxis("Vertical");

     // Find out the direction in which the camera is pointing
     Vector3 forward = (cameraTransform.forward*2-cameraTransform.forward);
     Vector3 right = (cameraTransform.right*2-cameraTransform.right);

     forward.y = 0;
     right.y = 0;

     forward.Normalize();
     right.Normalize();

     moveDirection = (forward * vertical)+(right * horizontal);


     // change direction of the player to the walking direction
     transform.forward = moveDirection;

     // save last position for colider
     lastPosition = charController.transform.position;
 }

 moveDirection.y -= gravity * Time.deltaTime;
 charController.Move(moveDirection * (Time.deltaTime * movementSpeed));

}

As you can see, I first camera forward and right vectors and apply the values of the input axis. Well the problem is, i guess, that when the character moves i.e. 4 units to the right and 4 units to the top, he moves ~5.65 units diagonally (Pythagoras, c^2 = a^2+b^2).

So my first thought was, to find out the point where that diagonal line hits a 1/4 circle line and then calculate the new x and y values out of it. But I'm quite unsure where to start and how to exactly calculate that point (or alternatively scale down the above Vector).

Any ideas?

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

Answer by Statement · Dec 06, 2010 at 08:35 PM

Short answer for short version:

moveDirection = (forward * vertical)+(right * horizontal);
moveDirection.Normalize();
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 Tseng · Dec 06, 2010 at 09:03 PM 1
Share

Thanks! Now that you post it, I actually realized my error. Was pretty stupid kind of. I had Vector3.Normalize(moveDirection) somewhere there, but no assignment (as it originally was placed somewhere else and I later refactored the code but didn't change that to moveDirection.Normalize() or moveDirection = Vector3.Normalize(moveDirection) xD

avatar image Statement · Dec 06, 2010 at 09:38 PM 0
Share

It's easy to get code blind :) Glad you can move on now :)

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

No one has followed this question yet.

Related Questions

Wheel rotation help cant work out the problem? 0 Answers

Rigidbody regenerated acceleration movement ? 0 Answers

Accelerate slowdown Player movement 0 Answers

Acceleration with CC 0 Answers

Character Movement 2 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