# position relative to a transform's position and rotation.

I think I solved this a long while ago, but I can’t seem to find my previous work.

What I’m trying to do is pick out a position (a) that has a position (b) relative to that point(a) that will always be the same position relative to that point regardless of the point being moved or rotated.

Say having a position V(0,0,0) as point a. Then have the position V(0,1,0) as point b that will always be relative to that point. So if point a is rotated 90 degrees by it’s Z axis. point b would instead be V(-1,0,0) in world space but still V(0,1,0) in local space.

For some reason, I can’t remember what to do to get the position to be affected by the rotation. (through scripting)

1 Like
``````Vector3 pointA;
Vector3 pointB;
Quaternion rotationA;
Vector3 result = pointA + (pointB * rotationA);
``````

Unity - Scripting API: Transform.TransformPoint , -direction and inverse- variants may help you with this.

I’ve been playing around with what you guys suggested, but multiplying by rotation seems to go berserk if I rotate by anything but the z axis. I’m sure that’s where I’m messing up.

And I don’t think I have a clue on how to get TransformPoint working for this. Though, I’ve tried using Transform Direction, which is something I remember using when working on this before, but to no avail. Might’ve been something different.

Now I’m wondering if I managed to get it working perfectly before or if I just didn’t test the possibilities. Funnily enough, I think I worked on this about a year ago. Basically making a crosshair that would have a spot chosen randomly on a disk. It effectually works, but the points aren’t affected by the rotation.

Thanks for the help though.

Might cheat with Unity’s Random.UnitSphere function, and see how that goes.

EDIT: Okay, wow. After trying to search for more info… I finally landed on answer after changing words to search for that might have a relation.

Way simpler then what I had previously, and it seems to work perfectly. Just gotta figure out how it ticks now.

Thank you for the help.