Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Tuah · Jun 14, 2010 at 07:23 AM · vector3quaternionrotategravityvector

Rotating a character's velocity?

I'm coming along quite well in this project of mine, but I can't seem to get the turning quite sharp enough. As it is, when the player directs movement in a new direction, the velocity gradually changes to that direction. It makes for some slightly slide-y controls. So I want to turn the direction of the velocity instead. The closest thing I've come up with so far is this:

rigidbody.velocity = Vector3.RotateTowards(rigidbody.velocity.normalized, desiredVelocity.normalized, Handling*Time.deltaTime, 1000)*rigidbody.velocity.magnitude;

And it works great on a flat plane, but my character is going to be walking on walls and riding bumpy surfaces as well. This particular function makes the character stop doing that, and almost makes it stop adhering to gravity.

If anybody has skill with Vector3's or Quaternions, this noob would be quite grateful for help! ^^;

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

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by james flowerdew · Sep 07, 2010 at 01:32 PM

What we do is grab the magnitude of the momentum/velocity then multiply it by a normalized vector representing forwards in the new chosen direction. this makes the objects turn without drag, skid or slow-down.

As a note hard setting the velocity of rigid bodies might make the physics look a little odd, but we also frequently like to rely less on applying forces (which can look a bit rubbery and unresponsive), and direct manipulation of velocity etc is "usually" fine.

Cheers,

James

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 StephanK · Jun 14, 2010 at 07:33 AM

Changing a rigidbodies velocity is most often not the best solution. I don't know what kind of game you are creating, so maybe this answer is completly useless.

Instead of changing the velocity directly you should apply forces to it. By balancing the strength of the forces and the drag of the rigidbody you should be able to get the wanted control feeling.

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 giantkilleroverunity3d · Jun 27, 2019 at 07:37 PM 0
Share

Changing a rigidbodies velocity is most often not the best solution

This is also expressed in the unity doco at some points. I have to whole heartedly agree with this. $$anonymous$$ost of the answers work in one direction or on a 2d design game but when the Go 3d orientation comes into play the developer can run into gimbal lock or velocity being applied in a direction that is opposite to the actual direction the GO is vectored or Quaterioned to. The developer will see the GO bouncing strangely or traveling in reflective directions ins$$anonymous$$d of continuing in the supposed direction.
avatar image
0

Answer by HolBol · Jul 26, 2010 at 11:11 AM

Just add a constant force too it instead, and limit the drag, and it'll do just what you want :).

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

1 Person is following this question.

avatar image

Related Questions

Rotate vector around vector? 2 Answers

Rotating wrong 0 Answers

moving object whilst keeping a constant y position 3 Answers

Rotate AI towards target, on single axis? 1 Answer

Rotate Towards doesnt work as expected 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