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 Ultermarto · Nov 28, 2013 at 01:17 AM · velocitydirectiongeteuler anglesnormalized

Getting the velocity direction as a euler angle.

Hello peoples,

I need a way to get the direction than an object is travelling in, as a Euler angle. In fact it might be worth mentioning what I'm actually trying to do, just in case there is an easier way. ahem

I'm working on a little demo where your character has to avoid being blown off the level by the wind. I managed to implement the wind with a simple Character.transform.AddForce, but since this runs every cycle, the force acting on my character increases constantly. So my idea was to try and simulate what happens in real wind; divide the force added by the wind with the speed with which the character is already being blown, thus, they can never exceed the windspeed itself.

Sorry about that. Anyway, as far as I know I need to get the direction of movement for my character as a euler angle, so that I can compare this euler angle to the wind direction itself. I've heard of normalizing, but it doesn't seem to return a euler angle and I'm not sure how to change that.

Please help.

Comment
Add comment · Show 1
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 Josh707 · Nov 28, 2013 at 02:33 AM 0
Share

The velocity of your character is the direction you are headed in, normalize just brings the values between 0 & 1 while maintaining the same direction, so you can use that direction without having really large values.

I'm not too sure what you mean by as a euler angle, that's just a Vector3 but named for rotation.

In your case the velocity normalized should be what you're looking for. If you want to test it, you can draw a line from your character to his position plus the normalized velocity to see if it's showing the right direction.

 void Update(){
     Vector3 vel_n = yourVelocity.normalized;
     Debug.DrawLine(transform.position, transform.position + vel_n, Color.red, 0, true);
 
 }

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by SilentSin · Nov 28, 2013 at 03:36 AM

Trying to express velocity as a euler angle makes zero sense. Your problem can be solved, it just has nothing to do with euler angles.

The reason in real life that things don't keep getting faster from find isn't because the force being applied by the wind decreases, its because of drag.

If you give the rigidbody some drag, that will slow it down for you. As the object gets faster, drag will start to have more of an effect until eventually the acceleration from the wind force is being perfectly cancelled out by drag each frame, which would be your maximum speed. Calculating the max speed requires some relatively complicated math, I usually just tweak the drag value manually until it achieves the results I want.

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 Ultermarto · Nov 29, 2013 at 05:12 PM 0
Share

Seems to work, except that my character falls at a slightly slower speed. But this isn't supposed to be anything fancy, so it'll do.

avatar image
0

Answer by robertbu · Nov 28, 2013 at 02:29 AM

My first thought is to use Vector3.Dot(). Untested:

 var dot = Vector3.Dot(windVelocity.normalized, rigidbody.velocity.normalized);
 var dot = Mathf.Clamp01(dot);  // Gets rid of negative values
 var windSpeed = windVelocity.magnitude;
 var bodyWindSpeed = rigidbody.velocity.magnitude * dot;
 var bodyWindSpeed = Mathf.Clamp(bodyWindSpeed, 0.0, windSpeed);
 rigidbody.AddForce(windForce * (maxWindSpeed - bodyWindSpeed) / windSpeed);

'windVelocity' is a vector representing both the direction and magnitude of the wind and needs to be defined and set elsewhere. 'bodyWindSpeed' is the speed of the object in the direction of the wind.

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

18 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

Related Questions

script to add force to the ball in a football game! 1 Answer

How can I convert velocity/direction to Force? 3 Answers

Switching between areas in a scene with triggers 0 Answers

velocity direction 1 Answer

How to let the vectory turn a direction? 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