Little Math/Vector question

Hi,

I’m terrible at Vector math, so I need some help…

I’m moving my character with code like this :

moveDirection = new Vector3(pad.position.x, 0,pad.position.y) * 1.5f;
rigidbody.MovePosition (rigidbody.position + moveDirection * Time.deltaTime);

In this code, pad.position is a Vector2.

But now I need to rotate this by 45 degrees. So I would need to either rotate the Vector2 by 45 degrees, or moveDirection around the Y axis. What would be the best way do achieve this? I know there has to be a simple way, but I can only think of slightly complicated ways…

Thanks!

I think the simplest solution is to do manual matrix multiplication, which isn’t so bad since its 2D and you have a fixed 45° angle:

tiltedVector = new Vector2(v.x - v.y, v.x + v.y) * 0.707;

or

tiltedVector = new Vector2(v.x + v.y, -v.x + v.y) * 0.707;

depending on the direction of rotation. v.x and v.y are the x and y components of the original moveDirection vector.

Thanks, it works perfectly!