- Home /
Vector movement according to rotation glitching out at non-square angles.
I'm trying to get my camera to not go through meshes, so that the player is unable to look through terrain/walls etc. I decided to use spherecasts for this, and it's working fine. However, if I change the player's rotation, all of my nice lovely transform offset stuff gets ****ed up. I've narrowed it down to the fact that I've been trying to use Vector subtraction, without actually taking in the rotation into account. My current code is really simple:
PositionOffset = transform.position - Target.transform.position;
Now, how would I adjust this so that if my player is at a 45 degree angle at the start of the game, PositionOffset's x will be how far to move (relative to the player's transform.right), same with Y & Z. I'm wondering if I'll need to do something like Vector3.Project
or Vector3.Cross
. What should I use?