2D Topdown Shooter - Player Movement Relative to Mouse
- by Jarmo
I'm trying to make a topdown 2D space game for my school project. I'm almost done but I just want to add a few little things to make the game more fun to play.
if (keystate.IsKeyDown(Keys.W))
{
vPlayerPos += Vector2.Normalize(new Vector2(Mouse.GetState().X - vPlayerPos.X, Mouse.GetState().Y - vPlayerPos.Y)) * 3;
rPlayer.X = (int)vPlayerPos.X;
rPlayer.Y = (int)vPlayerPos.Y;
}
if (keystate.IsKeyDown(Keys.S))
{
vPlayerPos += Vector2.Normalize(new Vector2(Mouse.GetState().X - vPlayerPos.X, Mouse.GetState().Y - vPlayerPos.Y)) * -3;
rPlayer.X = (int)vPlayerPos.X;
rPlayer.Y = (int)vPlayerPos.Y;
}
This is what i use to move towards and away from my mouse crossair. I tried to make a somewhat similar function to make it strafe with "A" and "D". But for some reason I just couldn't get it done.
Any thoughts?