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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
3
Question by Michel Verheughe · Dec 16, 2012 at 01:54 PM · velocitymagnituderidigbody

Direction of rigidbody.velocity.magnitude

I have a ridigbody that I move with AddForce. Then I read the speed with: rigidbody.velocity.magnitude

That gives me the speed in meters per second. Splendid! But now, I need to know if the speed (of a vessel) is forward or astern. The magnitude always returns a positive speed, but when astern, I need to read it as a negative speed.

I am sure that it is a very simple question but I can't find the answer anywhere. Thanks in advance.

Cheers, Michel

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
15
Best Answer

Answer by Bunny83 · Dec 16, 2012 at 02:34 PM

@XienDev is right.

The easiest way to get the velocity relative to your object is:

     var localVel = transform.InverseTransformDirection(rigidbody.velocity);

now localVel.z is the local z axis velocity part which will be positive when moving forward and negative when moving backward. Furthermore you have localVel.x which is the sideward speed (positive == moves right, negative == moves left) and localVel.y which is the up / down speed (positive == up, negative == down).

Comment
Add comment · Show 4 · 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 Michel Verheughe · Dec 16, 2012 at 03:54 PM 0
Share

Thank you both for your answers. Just out of curiosity, how did you get to know about something like, InverseTransformDirection? I have been working for more than 10 years with Flash ActionScript and now, I start with Unity, an excellent tool but I find the scripting ... a bit cryptic! ;-)

Cheers, $$anonymous$$ichel

avatar image XienDev · Dec 16, 2012 at 04:00 PM 0
Share

Open unity scripts docs, and learn about component u use

avatar image Bunny83 · Dec 16, 2012 at 04:34 PM 1
Share

Actually that's basic 3D stuff ;) I never really used Flash (only a bit AS2 back the old days :D). To me most AS stuff looks cryptic ;) Anyway here's the AS3 equivalent: globalToLocal

Ins$$anonymous$$d of InverseTransformDirection you could also use the worldToLocal$$anonymous$$atrix.

That's all pure vector math. (This is actually the moment your math $$anonymous$$cher was talking about.) Those functions exist in almost every game engine. The concept and the names of those functions might vary, but if you have understand what it does, the name of a function should give you an idea ;)

Just browse the docs on the major classes components just to see what a class is offering.

Here's a list of the most important components:

  • Transform

  • Rigidbody

  • $$anonymous$$onoBehaviour

  • All sorts of Colliders

  • Camera

  • All sorts of Renderer

  • Or in general the class hierarchy

Some important or useful non component classes:

  • GUI, GUILayout, the Event class and the OnGUI callback

  • the Input class

  • $$anonymous$$athf

  • the Debug class

I could mention a lot more, but it depends on your needs. Physics, Networking, Pathfindng, dynamic object creation there are tons of untility classes and functions in the Unity API. Just search and you'll find ;)

avatar image Michel Verheughe · Dec 16, 2012 at 07:39 PM 5
Share

Thank you Bunny. I know that I have to do a lot of reading but ... I am 64 years old and when you will be my age ... you'll understand why I am happy that I still know how to switch on my computer ... most of the time! LOL!

avatar image
4

Answer by XienDev · Dec 16, 2012 at 02:10 PM

rigidbody.velocity - it's velocity vector in world space, magnitude - it's length

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

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

InvokeRepeating faster if the rigidBody is moving faster? 1 Answer

force.normalized * magnitude 1 Answer

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

Rigidbody magnitude comparison is not working correctlly? 2 Answers

Animation velocity and magnitude 0 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