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 Novodantis 1 · May 20, 2010 at 11:12 PM · physicsrigidbodyvelocityairplane

What is the velocity on a given axis of a rigidbody?

I'm looking to find out what the velocity of a rigidbody is on a specified local axis.

I'm building a simulation/shooter based on scifi airship warfare, which includes both planes and floating anti-gravity airships. For the planes, I'd like to get the speed along the z-axis for a simplified calculation of lift. In aerial geek-talk, I'm basically interested in Indicated Airspeed.

For the airships, it will be used to aid calculating collision damage, hopefully in conjunction with a normal-line between the colliding parts. The logic is that fast-front hitting damage will do more than a gentle glancing bump.

Can anyone suggest the most efficient way to do this? I'm really looking for the closest actual equivalent to "rigidbody.GetLocalVelocity(z);"

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

2 Replies

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

Answer by Peter G · May 21, 2010 at 01:33 AM

You could do what the Car tutorial does. To find the local velocity it goes:

function Update () {

 //find the local velocity of the rigidbody.
 var relative : Vector3 = transform.InverseTransformDirection(rigidbody.velocity);

}

or when you use OnCollisionEnter(col : Collision), consider using Collision.RelativeVelocity.

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 Novodantis 1 · May 21, 2010 at 09:34 AM 0
Share

Aha, I shall try this at the first opportunity, I think it's just what I'm looking for. And Collision.RelativeVelocity was not something I was aware of either; thanks for that! That will make the airship part of the problem vastly simpler.

avatar image Novodantis 1 · May 21, 2010 at 10:43 AM 0
Share

Works perfectly. Thanks!

avatar image XaeroDegreaz · Jul 25, 2012 at 12:40 AM 0
Share

Thank you, this works as described.

avatar image
0

Answer by qJake · May 20, 2010 at 11:49 PM

I'm confused. Why can't you just use Rigidbody.velocity.x/y/z , or GetLocalVelocity(), as you said?

You could also write your own speed calculator, just save the x/y/z position from the previous Update and then subtract it from the current one, which gives you the speed. Something along the lines of:

float lastPos; float speed;

void FixedUpdate() { speed = Mathf.Abs(lastPos - transform.position.z); // or position.x/y if you need that lastPos = transform.position.z; // or x/y. }

Comment
Add comment · Show 10 · 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 Novodantis 1 · May 21, 2010 at 09:19 AM 0
Share

rigidbody doesn't have a GetLocalVelocity method, but if it did it would be exactly what I'm looking for. Apologies for confusion. -- rigidbody.velocity.x/y/z is in world space. I'm looking to know the objects speed relative to it's own axis.

avatar image qJake · May 21, 2010 at 10:01 PM 0
Share

What do you mean relative to its own axis? A game object only has local coordinates if it has a parent object...?

avatar image Novodantis 1 · May 22, 2010 at 06:18 PM 0
Share

All objects have their own co-ordinate space, this is effectively what a Transform is. The 'local' coordinates for positioning a child object are in fact it's position in the parents coordinate space. And the reason I need this forward speed is because airflow only provides lift when passing over the wings in the direction of the centre line (z axis of the aircraft). The same amount of movement in a vertical direction (for example) would not produce lift.

avatar image qJake · May 22, 2010 at 08:28 PM 0
Share

Right, but you still need to get the global velocity of the entire plane, the wings don't move independently of the plane, they're attached, so even though you need the Z-velocity, it needs to be the global velocity. I'm pretty sure Rigidbody.velocity.z is what you need.

avatar image Novodantis 1 · May 25, 2010 at 06:57 PM 0
Share

I did try to use Rigidbody.velocity.z, before I realised it was in global terms. Global z is essentially your movement 'north/south' right? (to avoid confusion of what I mean here) If you were to head 'east', your global z coord won't change. So your speed readout would be zero. Zero in the north/south direction, yes, but this is not what I needed. I needed the speed along the forward/back axis of the aircraft, not the world, which is what the above car tutorial snippet gives =)

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

2 People are following this question.

avatar image avatar image

Related Questions

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

2d side scrolling problem 5 Answers

Rigidbody character controller can't walk on stairs 0 Answers

Character Joints and Animations results in strange physic animation 1 Answer

Gravitational Object Creation for 3D Game 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