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 · May 24, 2013 at 03:19 PM · vector3dragwind

Scale a Vector3 Force depending to alignment of a Drag Vector3

Hi,

I like to simulate wind on a helicopter. The helicopter has different drag values and is flying in the air (CGM rc Heli Simulator). The goWind object is a seperate object where the wind is calculated and stored in it's transform coordinates. 0,0,0 means no wind. 0,0,0.5 means wind from left. What I try to do is, to add the wind force in the correct strength, depending to the orientation of the helicopter. The force direction is working, but the strength of the wind force is not scaled as wanted.

 // This script is attached to the helicopter with rigidbody and other physic calculations
 private var drag:Vector3 = Vector3 (0.2,5.0,0.2); // Helicopter Drag: sideways, up-down, forward
  
 function FixedUpdate () {
     var windDrag:Vector3 = Vector3.Scale(goWind.transform.position, drag);
     rigidbody.AddForce (windDrag, ForceMode.Impulse);
 }

Best regards and thanks in advance for help, Klaus

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 robertbu · May 24, 2013 at 03:35 PM 0
Share

Scaling one force by another doesn't make make much sense to me. Typically you want to add forces together. That is drag is one force, and wind is a second force.

avatar image Klaus-Eiperle · May 24, 2013 at 06:46 PM 0
Share

Thank you very much for your comment. $$anonymous$$aybe I have named that wrong. Drag is the air resistance of the helicopter. So the higher drag is in one axis, the more the force can move the helicopter in this axis.

1 Reply

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

Answer by robertbu · May 25, 2013 at 12:02 AM

I see one problem that may account for the "force not scaled as wanted." I'm assuming the helicopter is allowed to turn and that 'drag' is defined in terms of the helicopter (and therefore it is a local coordinate). windDrag is calculate as a world vector. You need to convert drag into world coordinates before you do you calculation. See Transform.TransformPoint() to make the conversion.

I'm only seeing a very small piece of the code, but it seems to me that what you really want is the relative wind direction. That is you add the negated velocity vector of the helicopter with the velocity of the wind and apply the drag to the result.

Comment
Add comment · Show 8 · 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 · May 25, 2013 at 05:59 PM 0
Share

Thank you very much for your reply.

Yes, the helicopter is allowed to turn and 'drag' is defined in terms of the helicopter. 'drag' is a local coordinate. The wind force is a world vector. The x, y and z position values assign the strength and direction (relative to 0,0,0).

When I convert 'drag' to world coordinates, I get a wrong result. The wind increases depending to the position of the helicopter because the world coordinates get also the position of the helicopter i the world. Then I have tried to remove the helicopter position from these coordinates to get only the alignment coordinates for the multiplication with the force. But that doesn't work as expected. $$anonymous$$aybe I'm on a wrong path.

I have to scale the wind force depending to the angle alignment of the helicopter (not the position). $$anonymous$$aybe I have to solve that with angle calculations for each axis seperately.

A wind zone object which uses the physic of a piece of paper would be the solution.

avatar image robertbu · May 25, 2013 at 07:13 PM 0
Share

You are right that Transform.TransformPoint() is the wrong thing to use. I think you want:

 var worldDrag = transform.rotation * drag;

I don't have time at the moment to test it. If this doesn't work, let me know. Since I now understand what you want, I should be able to work it out.

avatar image Klaus-Eiperle · May 26, 2013 at 08:03 AM 0
Share

Thank you very much for pointing me in the right direction.

This is the solution:

 // This script is attached to the helicopter with rigidbody and other physic calculations
 private var airResistance:Vector3 = Vector3 (0.15,1.0,0.07); // Helicopter air resistance: sideways, up-down, forward
 private var goWind:GameObject;    // reference to the Game Object 'Wind'
 
 // cache this for performance reasons
 private var _transform:Transform;
 private var _rigidbody:Rigidbody;
 private var _goWindTransform:Transform;
 
 function Awake() {
     _transform = transform;
     _rigidbody = rigidbody;
     goWind = GameObject.Find("Wind");
     _goWindTransform = goWind.transform;
 }
 
 function FixedUpdate () {
     // calculates air resistance depending to the alignment of the helicopter
     var corrAirRes:Vector3 = _transform.rotation * airResistance;
     var resWindDrag:Vector3 = Vector3(
         $$anonymous$$athf.Abs(corrAirRes.x)*_goWindTransform.position.x,
         $$anonymous$$athf.Abs(corrAirRes.y)*_goWindTransform.position.y,
         $$anonymous$$athf.Abs(corrAirRes.z)*_goWindTransform.position.z);
     _rigidbody.AddForce (resWindDrag, Force$$anonymous$$ode.Impulse);                // add the wind to the helicopter
 
     var pointA:Vector3 = _transform.position - Vector3.forward*0.5;        // visual debugging
     var pointB:Vector3 = pointA + resWindDrag;
     Debug.DrawLine( pointA, pointB, Color.red);
 }
avatar image Klaus-Eiperle · May 26, 2013 at 07:44 PM 0
Share

There must be still a bug in that calculation in line 19. When the helicopter is blown from left, the resWindDrag is lower than when it is blown from right... a.s.o. So I tried to limit the angle values. But that doesn't work as expected.

 var corrRotation:Quaternion = Quaternion.Euler(
   (_transform.rotation.eulerAngles.x+180)%180, 
   (_transform.rotation.eulerAngles.y+180)%180, 
   (_transform.rotation.eulerAngles.z+180)%180);
 var corrAirRes:Vector3 = corrRotation * airResistance;

I don't have any idea how to fix that.

avatar image robertbu · May 26, 2013 at 07:54 PM 0
Share

I'll take a look this evening. Just to make absolutely sure, _goWindTransform represents a vector that is the direction and magnitude of the force of the wind in world coordinates. On a quick read, your $$anonymous$$athf.Abs() seems wrong to me.

Show more comments

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

13 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

Related Questions

Touchscript drag constraints 1 Answer

Drag rigidbody to crosshair 0 Answers

Drag-and-drop dot on mobile 2D 0 Answers

Drag object in unity 2d with moving camera 0 Answers

Keep vectors exactly 15 distance apart 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