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
0
Question by Gibbonuk · Dec 20, 2016 at 03:24 PM · physicsvelocity

Finding Velocity at point but locally....

Hi, Im not sure why im finding this so difficult but I am for some reason. I have a moving body which can go in all directions and I am trying to find the velocity in the X direction of a POINT on that object.

I can find the X Velocity of the rigid body by simply doing the following:

 float xVel = transform.InverseTransformDirection(targetObj.GetComponent<Rigidbody>().velocity).x;

The above works fine, but this doesnt do at a specific point...

So I have tried so far:

 leftVel = this.GetComponent<Rigidbody> ().GetRelativePointVelocity (leftPos.transform.localPosition).x;

But leftvel still changes depending on the direction of the rigidBody...

I have tried using just the GetPointVelocity and then inverseTransformDirection but I get the same problem?

I have tried the above but also transforming the local leftPos but same problem...

What am i doing wrong?

Thanks

Comment
Add comment · Show 1
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 Glurth · Dec 20, 2016 at 04:13 PM 0
Share

RigidBody.Velocity is in WorldSpace, so when you do pass it through InverseTransformDirection, you are converting it to local/model Space coordinates. Is that your intention? You want the model-space velocity of a point?

Also note that GetRelativePointVelocity takes as a parameter, a world-space coordinate, but you are passing it a localPosition (modelspace) coordinate.

So: to get the local velocity of the world point:

   leftVel = transform.InverseTransformDirection((this.GetComponent ().GetRelativePointVelocity (leftPos.transform.position)).x;


Edir: oops! I was looking at GetPintVelocity, Not getPointVelocityRelative in the docs! ignore all that pls.. ok, after review- I think issue may still be the "space" of the point you are providing. note that this objects local modelSpace, leftPos.transform.localPosition, is NOT the same model space as this.transform. In order to get it to the correct space, you would need to apply the inverse of this.Transform to the world space coordinate of the leftPos transform. e.g.

 localPositionToCheck = transform.InverseTransformPoint(leftPos.transform.position);

In this case, I'm assu$$anonymous$$g that the doc's "RelativePoint" is in localSpace: I have NOT tested this. they could mean relative in world-space. in which case we would want to use:

 positionToCheck = transform.position-leftPos.transform.position;

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by oswin_c · Dec 20, 2016 at 03:50 PM

I am assuming that you are trying to get the point velocity relative to transform.left of the rigidbody.

I look at your code and I cannot see what is going wrong . If local to world space transforms, coordinate systems, the meaning of .x in local space, confuse you, and have unexpected results, you are by no means alone -- I have the same problem and I'm no girl next door.

This is why I generally discourage using .x, .y, .z components if at all possible -- there's no reason to make yourself dependent on a coordinate system when we have vectors and quaternions. There's a simple and slick way of doing this that will give you the point velocity no matter what.

My suggestion (not tested) is to start by trying this:

 leftVel = Vector3.Dot(
     this.GetComponent<RigidBody>().GetRelativePointVelocity(leftPos.transform.localPosition),
     this.transform.left
 );

If the code is doing what you think it is doing, this should give you exactly the same answer as getting the .x component. In that case, I suggest taking a close look at your object's behavior -- maybe that makes sense. However, I have a hunch it's not doing what you think it's doing, and I've run into problems with using components in unity before, which is why I stopped.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Throwing knife doesn't throw correctly 0 Answers

Angular Friction 0 Answers

Convert from m/s to m/fixedFrame 1 Answer

Naturally make velocity 0 2 Answers

Problems with rotating an object using angular velocity. 2 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