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 /
  • 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.

avatar image p3er Bunny83 · Sep 22, 2016 at 12:29 PM 0
Share

The 500 is just a temporary multiplier to boost the grip level higher so I can see whether it works or not. Right now it doesn't seem to work. If I apply grip to the front wheels only, what I expect to see is that the car just spin out instantly, however I'm getting some very strange results. It appears as if the lateral velocity testing is actually world oriented but I'm not sure. One thing i can safely conclude is that InverseTransformDirection isn't the right function for what I'm doing.

avatar image p3er Bunny83 · Sep 22, 2016 at 12:34 PM 0
Share

And yes, I have tried drawing lines and it appears to do what I want to but the driving aspect is very glitchy. The car works somewhat driving straight but as soon as you reach 90 degrees turning it starts to glitch out very quickly. Honestly, I'm not sure exactly what it's doing. It changes all the time as I change my experiments. But what I want is to read the velocity of the main rigidbody scoped trough the rotation of the wheel child. Basically.

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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Random move,Random move and rotation 0 Answers

How to attatch two objects at their children, with child rotation 0 Answers

mimicking movement of one object to another with different scale/location. 1 Answer

Moving and rotating object to specific point (3D) 1 Answer

How to keep position of child as is, while its parent rotation unwantingly causes the child to change position due to it's edge positioning relative to the parent? 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