#Vector math refresher
1 messages · Page 1 of 1 (latest)
Assume the bottom black dot is 0, 0, and the direction is 0.7, 0.7 lets say. Assuming some object or player is facing that direction, I want to get the local offset from that direction, lets say (1, 0) (dotted line indicates where it roughly should be)
Been a while since Ive done vector math like this so would appreciate a refresher!
So, using a local direction you want a local offset?
cross(direction, planeNormal) gives you the orthogonal normal of the direction in the plane. 2D is just 3D with the planeNormal being (0,0,1)
Vector2.Perpendicular does this
Or (x ,y) -> (-y, x)
If I even understand the issue correctly
Just add the offset vector to the position of the player. If I understand the question properly... Which I'm not sure I do as the diagram isn't that clear about what you're looking for.
Probably shouldve made it a bit more clear in the diagram, but my question was to add the offset based on the local direction
So in the diagram I made earlier, (-1, 0) from the direction dot would be 1 unit to the left, but because of the directional vector it gets shifted
But I did end up solving this with a different approach, Ill share it here if I get around to it later
Vector3 localOffset = new(-1, 0);
Vector3 worldPoint = transform.TransformPoint(localOffset);```
or if you don't want it affected by the object's scale:
Vector3 localOffset = new(-1, 0);
Vector3 rotatedOffset = transform.rotation * localOffset;
Vector3 finalPoint = transform.position + rotatedOffset;```
Vector2 spawnDirection = projectileSpawnRule.SpawnLocalOffset.normalized;
Vector2 right = new Vector2(lookDirection.y, -lookDirection.x);
Vector3 spawnPos = (Vector2)transform.position + lookDirection *
spawnDirection.y + right * spawnDirection.x;
Something like this is what worked for me
slight limitation because I didnt have access to transform.TransformPoint since I wanted to get the position for another object