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 /
  • Help Room /
avatar image
0
Question by Flynxi · Oct 29, 2020 at 03:31 AM · rigidbodyrigidbody.addforce

Rigid body movement system faster at diagonals

Hey All,

This is my first question on the forum so sorry if I don't provide enough information (I post a lot on stack exchange so I will just do what I would do there).

I am currently trying to make a rigid body player movement system using forces. Since doing this will allow me to update the mass of the player (if they are carrying more or less equipment), have different drag values on different surfaces (If you are on ice or concrete movement would be different), and have a modifier on the default force amount (so if I implement a skill system where a skill would make you move faster I would just add a multiplier to the default force). I originally started by trying to implement a clamp on the velocity of the player but this isn't needed when you have drag and weight will only allow a maximum movement speed by default. The issue I am currently running into is when adding force in the forward direction (lets say the maximum magnitude with my set weight/drag is 3 when moving forward) and in the sideways direction (lets say the maximum magnitude with my set weight/drag is 1.5 when moving left/right) but the total magnitude is actually much higher than I would want. So if you hold the "w" and "a" key at the same time then look a little to the right so you are moving diagonally towards you where you want to go you are actually moving FASTER than if you are just pointing directly at the location and holding "w". I was trying to think of a way to get around this but I don't have a good enough understanding of the physics system to accomplish my goal. Here is a snippet of my code below so you can see what I am doing (I have different states for each standing/proning/crouching so I cut out some of the code to make it quicker to read):

    void move_forward()
     {
         switch (movement_standing_state)
         {
             case movement_standing_states.prone:
                 switch (movement_speed_state)
                 {
                     case movement_speed_states.slow:
                         move_player(local_player_rb.transform.forward, slow_prone_forward_force);
                         break;
                     case movement_speed_states.normal:
                         move_player(local_player_rb.transform.forward, normal_prone_forward_force);
                         break;
                     case movement_speed_states.fast:
                         move_player(local_player_rb.transform.forward, fast_prone_forward_force);
                         break;
                 }
                 break;


Coupled with a move left function:

 void move_left()
     {
         switch (movement_standing_state)
         {
             case movement_standing_states.prone:
                 switch (movement_speed_state)
                 {
                     case movement_speed_states.slow:
                         move_player(-local_player_rb.transform.right, slow_prone_sideways_force);
                         break;
                     case movement_speed_states.normal:
                         move_player(-local_player_rb.transform.right, normal_prone_sideways_force);
                         break;
                     case movement_speed_states.fast:
                         move_player(-local_player_rb.transform.right, fast_prone_sideways_force);
                         break;
                 }
                 break;

And the actual add force function:

 void move_player(Vector3 direction, float force)
     {
         local_player_rb.AddForce(direction * force);
     }

Thank you for any help ahead of time!

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 LaphicetCrowe · Oct 29, 2020 at 08:12 AM

Normalise the movement direction, or else the speed will stack at diagonals.

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 Flynxi · Oct 29, 2020 at 06:22 PM 0
Share

If I am understanding you correctly, if I added all the movement vectors and doing only one add force call, but normalize the vectors beforehand? I might not be understanding it correctly but wouldn't this cause the vector to just have a magnitude of 1 in said direction?

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

Steering a Spaceship using rigidbody 0 Answers

Counteracting rigidbody velocity using AddForce? 0 Answers

How to change rigidbody force direction? 1 Answer

Player rigidbody jumping continues infinitely 1 Answer

revolving a rigidbody around another MOVING rigidbody 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