AlfonsAberg
Is there a way to get the angle from the thumbsticks of a XBOX360 controller
If up return 0, right 90, down 180, left 270.
this is how I crudely did it:
if (currentGamePadState.ThumbSticks.Right.X != 0 || currentGamePadState.ThumbSticks.Right.Y != 0)
{
if (projectileTime == 0)
{
Vector2 vel = new Vector2(400, 0);
float rad = 0;
if (currentGamePadState.ThumbSticks.Right.Y == 0)
{
if (currentGamePadState.ThumbSticks.Right.X > 0)
{
vel = new Vector2(400, 0);
}
else
{
vel = new Vector2(-400, 0);
}
}
else if (currentGamePadState.ThumbSticks.Right.X == 0)
{
if (currentGamePadState.ThumbSticks.Right.Y > 0)
{
vel = new Vector2(0, -400);
}
else
{
vel = new Vector2(0, 400);
}
}
else
{
if (currentGamePadState.ThumbSticks.Right.X > 0)
{
rad = (float)Math.Atan((double)currentGamePadState.ThumbSticks.Right.Y / currentGamePadState.ThumbSticks.Right.X);
vel = new Vector2((float)Math.Cos(rad) * 400, (float)Math.Sin(rad) * -400);
}
else
{
rad = (float)Math.Atan((double)currentGamePadState.ThumbSticks.Right.Y / currentGamePadState.ThumbSticks.Right.X);
vel = new Vector2((float)Math.Cos(rad) * -400, (float)Math.Sin(rad) * 400);
}
}
ProjectileManager.AddProjectile(Game1.Players[0].playerSprite.Position, vel, Color.Red);
projectileTime = 200;
}