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 Anders9009 · Aug 26, 2014 at 04:44 PM · speeddirectionchangerigidbody physics

Changing direction without altering velocity

Im making a tribes style game (if you need context to my question) and i want you to be able to slightly control you direction when going at high speeds. The players rotation is independent of the direction you are going so i cant use the "side to side" axis. How should i go about this? Should i make an item that follows the players travelingdirection and base it on that or is there any other way. Like using rigidbody.velocity or something...

Comment
Add comment · Show 3
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 robertbu · Aug 26, 2014 at 04:48 PM 0
Share

This is hard to answer without knowing how something turns. You can do something like this:

 rigidbody.velocity = Quaternion.AngleAxis(10.0 Time.deltaTime) transform.up) * rigidbody.velocity;

If this is applied every frame, you will see a 10 degree change in direction every second while maintaining the current velocity. Best if this line was executed in FixedUpdate(). If you want to keep some fixed speed, you can change the line to:

 rigidbody.velocity = Quaternion.AngleAxis(10.0 Time.deltaTime) transform.up) * rigidbody.velocity.normalized * someSpeed;
avatar image wibble82 · Aug 26, 2014 at 05:03 PM 0
Share

Could you describe the exact effect you're after. You're correct that it'll involve changing the linear velocity of the rigid body, but to work out what to change it by we need to know what effect you want.

avatar image meat5000 ♦ · Aug 26, 2014 at 06:27 PM 0
Share

Velocity incorporates a speed in a direction. Where

Speed = Distance / Time,

Velocity = Displacement / Time.

Just being a pedant, but your title is erroneous.

But it is owing to this that Velocity can be expressed in a Vector3. This makes it very easy to change direction but maintain speed. Normalise your direction vector and multiply it by your speed.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by LSPressWorks · Aug 26, 2014 at 05:40 PM

If I gather you are describing where, for instance the playing is running left, and can turn to the side while he continues to run along the same path leftward?

Is the motion being applied directly to the player, or is the player the child of an object that is producing the movement?

For stuff like that I drop the player in an empty object to apply velocities so that I can apply rotation to the character without it affecting directional speed. Thus the player can flop and rotate around all day under the controller object, while actual directional force is only applied to the controller.

you can "clip" the effect with an if statement to check the speed, and if I understand you correctly, turning radius decreases with speed? If that is the case you can you can divide your rotation factor by a portion of the velocity such as

 //--Check to see if we're above 92 velocity--//
      if(controllerObject.velocity.magnitude.normalized >= 92)
         { 
       //--Decrease turning sp with increase in relation to velocity above 92--//  
         rotSpeed = rotSpeedBase / ((controllerObject.velocity.magnitude.normalized -92) / 5);     
         
  //--reset to normal turning sp when under target speed--/
         }else
              {rotSpeed = rotSpeedBase;}

Bear in mind, that you may need to check with some if statements to be sure that you don't go under any problematic limits, like 0 when doing stuff like this.

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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Change the direction of velocity upon tapping a button!!?? 1 Answer

Final direction and velocity of two velocities [World Velocity and Local Velocity] 0 Answers

How to change pace by pressing different buttons once? 1 Answer

How do I script speed in java? 0 Answers

how to change pitch of sound without changing speed? wav file 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