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 Klaus-Eiperle · Jun 03, 2014 at 04:53 PM · rigidbodyvelocityvectorwind

Add a wind vector to local velocity for calculating wind speed

How can I add a wind vector to the velocity of a rigid body (in my case a helicopter) for reading the windspeed for the x-z axis?

My calculation below is working in cases where the wind is blowing directly to the x or z axis (0° or 90° angle) of the helicopter but when the wind is blowing for example in a 45° angle to the helicopter, the wind is sometimes 0 m/s.

 // this is the wind direction in world space which changes
 Vector3 wind=new Vector3 (-7.0f,0.0f,0.0f);
 
 // here I add the local velocity in world space to the wind in world space
 Vector3 _WindPlusVelocity = wind-rigidbody.velocity;
 
 // here I translate the WindPlusVelocity to the local space of the helicopter
 Vector3 _RelativeWindVelocity = _transform.InverseTransformDirection(_WindPlusVelocity);
 
 // when the heli flies with the wind, the VelZ is wind plus local velocity Z.
 // when he flies in the opposite direction, the VelZ is velocity Z minus wind.
 string Test1="_velY: "+(_RelativeWindVelocity.y).ToString("f1");
 string Test2="_velXZ: "+(Mathf.Abs(_RelativeWindVelocity.x+ _RelativeWindVelocity.z)).ToString("f1");

What I'm doing wrong?

Comment
Add comment · Show 2
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 Lovrenc · Jun 03, 2014 at 05:01 PM 0
Share

maybeyoushouldtrytoformatthecodeitissomucheasiertoreadthen.

avatar image Klaus-Eiperle · Jun 04, 2014 at 07:02 AM 1
Share

Please excuse me for that. Now I formatted it as code.

2 Replies

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

Answer by Klaus-Eiperle · Jun 04, 2014 at 02:06 PM

This is the solution:

 float _vwx = Mathf.Abs(rigidbody.velocity.x-wind.x);
 float _vwz = Mathf.Abs(rigidbody.velocity.z-wind.z);
 string Test2="VelXZwind: "+ (Mathf.Sqrt(_vwx*_vwx+_vwz*_vwz)).ToString("f1");
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 Tarlius · Jun 06, 2014 at 08:16 AM 0
Share

You realise that unless you have velocity on y, that is just a much more complex way to write what I wrote...? If you do have velocity in y you can do:

 Vector3 vw = rigidbody.velocity - wind;
 vw.y = 0;
 float v = vw.magnitude;

$$anonymous$$athf.Sqrt(_vwx*_vwx+_vwz*_vwz) is what magnitude is. You also don't need to bother with the Abs because when you square them you negate that anyway. (ie: -1 x -1 = 1).

Also, if you do have velocity in y, note that freefalling vertically will give you a speed readout of 0 (possibly intentional)

avatar image
0

Answer by Tarlius · Jun 04, 2014 at 08:48 AM

I think what you want to do is something more like...

 relativeVelocity = (selfVelocity - windSpeedVector).magnitude;

I'm not sure exactly what you are trying to calculate so not sure where the minus sign should be, but that should get you started.

Also, I think RigidBody.velocity is already in world space so you shouldn't need a conversion, but I could be wrong.

If you are trying to simply make the wind move the helicopter, you could (and probably should) just do it with RigidBody.AddForce, by the way.

If its for a UI component, (wind speed relative to helicopters speed, in km/h) you probably want to add the two together

Comment
Add comment · Show 3 · 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 Klaus-Eiperle · Jun 04, 2014 at 01:47 PM 0
Share

Thank you very much for your hint.

For calculating some helicopter physics I need two different speed values. One for the y axis (steering direction up and down) and one for the yz axis which describes the sideways movement.

I'm calculating XZ speed like this: absRelativeVelocityXZ = $$anonymous$$athf.Sqrt(absRelativeVelocity.x*absRelativeVelocity.x+absRelativeVelocity.z*absRelativeVelocity.z);

When I calculate the real speed (own speed plus wind speed) by using the magnitude, I don't have any access to the real speed for the local XZ axis of the helicopter.

avatar image Klaus-Eiperle · Jun 04, 2014 at 02:08 PM 0
Share

Yes, RigidBody.velocity is in world space, I simply need to convert it to local space when I like to read out a single axis.

avatar image Tarlius · Jun 06, 2014 at 08:16 AM 0
Share

On a side note, you should not do physics in anything but world space. The result get... odd.

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

23 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

Related Questions

Velocity powered rigidbody on a moving platform without parenting. 3 Answers

How can I find the velocity on a rigidbody which moves using Lerp? 1 Answer

How to check if an object has stopped moving? 5 Answers

Unity autojump script glitch 1 Answer

Preserving Velocity during rotations 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