Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by MirrorIrorriM · Jul 22, 2011 at 02:39 AM · rotationrigidbodyvelocityforcerelative

relative velocity of rigidbody according to rotation...

Hello all. I was messing around with programming tank treads. I'm simply using a texture that slides across a model to simulate treads. Thing is in order to move this I need to "fake" the treads moving along the ground. To do this I decided to just check if the treads are on the ground and use "rigidbody.AddRelativeForce" to move it forward when it is. So everything is working fine except one problem.

I don't know how to check the relative velocity to set a speed limit.

 if (Input.GetKey(Forward)){ //Forward is a custom set key
 if (Physics.CheckCapsule(transform.TransformPoint(0,-.6,-.4),transform.TransformPoint(0,-.6,.4),.09)){//This checks if you are on the ground
     if (rigidbody.velocity.magnitude < 5)//THIS is what I want to replace
         rigidbody.AddRelativeForce(Vector3(0,0,1)*Power);

 }}

Right now I am simply using "rigidbody.velocity.magnitude" to check the speed, but that only gives me the total velocity, I want the velocity relative to the direction the treads are pointing. That way if I am moving at the speed of sound sideways, you can still push yourself forward instead of having to wait for the tank to slowdown so you can move where you want to go. Another problem is if you were being pushed backwards you wouldn't be able to push back which would really suck. Anyway to make the velocity magnitude nice and rotated to only look at one axis of movement relative to the object? Specifically the Z axis?

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

1 Reply

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

Answer by hellcats · Jul 22, 2011 at 02:53 AM

You could just check the z component (rigidbody.velocity.z) instead of the magnitude.

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 MirrorIrorriM · Jul 22, 2011 at 02:57 AM 0
Share

rigidbody.velocity.z is relative to the world z axis. I need rigidbody.velocity.z but relative to the OBJECT'S z axis, which has been rotated.

avatar image hellcats · Jul 22, 2011 at 04:07 AM 1
Share

You could use transform.InverseTransformDirection(rigidbody.velocity) to transform the velocity into local space and then check the z component, or more efficiently you could compute the dot product of rigidbody.velocity and transform.forward using Vector3.Dot.

avatar image MirrorIrorriM · Jul 22, 2011 at 05:34 AM 0
Share

That's precisely the code I needed. Thanks!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

relativeVelocity how to? (noob question) 2 Answers

Rigidbody slowing right down when colliding only when I'm rotating the velocity to always be going forward 1 Answer

How to apply relative force to Ball using another object? 0 Answers

leftover rb.velocity.z that causes magnitude to spike randomly 0 Answers

How can you apply force or set the velocity of a rigidbidy on local axis? 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