• 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 /
  • Help Room /
avatar image
0
Question by p3er · Sep 22, 2016 at 05:06 AM · transform.positiontransform.rotationrigidbody.velocitytransform.parent

Velocity of parent local to child

         var vel = rigidBody.GetRelativePointVelocity(wheel_fr.localPosition);
         var tempvector = wheel_fr.right*-wheel_fr.InverseTransformDirection(vel).x;
         rigidBody.AddForceAtPosition(hitnormal_r*spring_strength*hitlength_r+hitnormal_r*hitdelta_r + tempvector*500 ,ray_origin_r,ForceMode.Force);
 
         vel = rigidBody.GetRelativePointVelocity(wheel_fl.localPosition);
         tempvector = wheel_fl.right*wheel_fl.InverseTransformDirection(vel).x;
           rigidBody.AddForceAtPosition(hitnormal_l*spring_strength*hitlength_l+hitnormal_l*hitdelta_l + tempvector*500 ,ray_origin_l,ForceMode.Force);

So what I'm working on is a car game with ray cast suspension. The car itself is a rigidbody with offset force application for each wheel. I got the suspension done nicely but i can't get the lateral grip to work properly. Essentially what I need is to read the velocity of the main car rigidbody but in the position and axis of the child/wheel. For some reason InverseTransformDirection doesn't do it for me even though alot of my google searches have led me to this function.

I'm lost. Any help appreciated! Thanks in advance

Comment
Add comment · Show 3
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 Bunny83 · Sep 22, 2016 at 12:03 PM 0
Share

I don't see any major mistakes. However keep in $$anonymous$$d that for this code to work, your "wheel" gameobjects need to be a direct child of the rigidbody, otherwise the localPosition is wrong.

If in doubt you can transform the world position into the local position of the rigidbody by using InverseTransformPoint of the rigidbody Transform.

However in that case it would be easier to use GetPointVelocity and just pass the world space position of the wheels.

Though if the wheels are direct childs of the rigidbody, your method should work just fine.

What exactly does mean:

doesn't do it for me

Your "500" looks a bit strange. magic numbers like this are dangerous. $$anonymous$$eep in $$anonymous$$d that the amount of force to cancel the slip velocity depends on the rigidbody mass. Have you tried using Debug.DrawRay to visualize your tempvector of each wheel?

I also would recommend to put all the logic for one wheel in a seperate method that just takes the wheel transform and a local direction vector specifying the direction of the wheel.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by p3er · Sep 22, 2016 at 05:41 PM

I think i've managed to further isolate the problem.. I've changed my mind about InverseTransformDIrection and it appears to be working. However it seems as if the offset velocity check doesn't work properly. Specifically this: vel = rigidBody.GetRelativePointVelocity(wheel_rl.localPosition);

I made this conclusion by drawing lines and figuring out that the tyres lateral speed is correct when the car is moving at a considerate speed however not when the car is stationary and rotating.

The wheels are direct childs of the rigidbody gameobject. I also tried subtracting the offset velocity with the rigidbody main velocity and it seems to give a net value of something else than 0 which is highly confusing..

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 p3er · Sep 22, 2016 at 06:02 PM 0
Share

Okay now it all works perfectly! Replaced vel = rigidBody.GetRelativePointVelocity(wheel_rl.localPosition);

with

 vel = rigidBody.GetPointVelocity(wheel_rl.position);


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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

object referance not set to instance of an object when accessing transform.position 0 Answers

Camerashake doesn´t work expected in Build c# 0 Answers

Get camera position back to starting position 0 Answers

how do i make an enemy look at the player only on the x axis and not on the y one,how do i make an enemy look at a player only on the x axis 0 Answers

Bugged Player Tp from position one to another 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