- Home /
geometry how to find ray local hit point?
I'm sorry but I just can't figure out but I've made it long way, ... how else to find local point with vector 3 instead of transform, ...
Transform parent = OuterProjectile.transform.parent;
OuterProjectile.transform.position = HitPoint;
OuterProjectile.transform.parent = transform;
BodyVulnerability = OuterProjectile.transform.localPosition.x;
OuterProjectile.transform.parent = parent;
this works exactly the way I want and all that is I'm searching for that:
BodyVulnerability = OuterProjectile.transform.localPosition.x;
information, ...
is there any else way to figure it out except with parenting, ...
sorry I'm really bad at geometry
EDIT: sorry did world position instead of local repairing the Q now, ...
I'm confused about what you are doing here. 'transform.position' is a world space position. It is not the local position shown in the inspector, so changing the parent does not change this position. Put a '`Debug.Log(OuterProjectile.transform.position.x);`' above and below your parenting code. You will see the value is the same. And given what you have done, the value should be the same as HitPoint.x
.
If you are looking for the local position (which this code does not do), you can use Transform.InverseTransformPoint().
Answer by jonnyhopper · Oct 24, 2013 at 08:24 PM
Hi!
Don't worry, this stuff can be confusing. I'm presuming you want the result local to whatever GameObject you're currently "in" - i.e. whatever holds transform. I think you should be able to do something like:
Vector3 local_point = transform.worldToLocalMatrix.MultiplyPoint3x4( Hitpoint );
Hope that helps J.
can you explain the code a bit please?
and you are presu$$anonymous$$g me correctly :)
sorry, typo on my code. it should be $$anonymous$$ultiplyPoint3x4
both codes work fine :) thanks to both but kinda I like more the not matrix, ...
BodyVulnerability = transform.InverseTransformPoint( HitPoint ).x;
BodyVulnerability = transform.worldToLocal$$anonymous$$atrix.$$anonymous$$ultiplyPoint3x4( HitPoint ).x;
may I ask what's the difference? they both work as I wanted, ...
You're right - InverseTransformPoint is a helper function to do exactly the same thing. Use that!
It's for convenience. It was added in Unity to mean you don't need to type worldToLocal$$anonymous$$atrix.$$anonymous$$ultiplyPoint3x4 etc - but its functionality is the same.
Your answer
![](https://koobas.hobune.stream/wayback/20220613120557im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to check if point is inside collider? 1 Answer