Hey guys,
I’m currently working on 3D top down shooter.
I want to controll my player movement with a xbox controller the same way as in games like “Gauntlet” or “Hellerdivers”. The aiming (turning arround) with the right stick works. The problem is that I dont’ want the movement to depend on the direction the character is facing.
When I move the controller to the left the player should move to the left (no matter its orientation).
This is my code:
void FixedUpdate()
{
// Amount to Move
float MoveVertical = Input.GetAxis("VerticalPlayer" + player.playerId) * movementSpeed * Time.deltaTime;
float MoveHorizontal = Input.GetAxis("HorizontalPlayer" + player.playerId) * movementSpeed * Time.deltaTime;
float MoveRotateHorizontal = Input.GetAxisRaw("RotateHorizontal" + player.playerId);// * rotateSpeed * Time.deltaTime;
float MoveRotateVertical = Input.GetAxisRaw("RotateVertical" + player.playerId);
if (MoveRotateHorizontal != 0 || MoveRotateVertical != 0)
{
float angle = Mathf.Atan2(MoveRotateHorizontal, MoveRotateVertical) * Mathf.Rad2Deg;
transform.eulerAngles = new Vector3(0, angle + aimAngleOffset, 0);
}
// Move the player
Vector3 movement = new Vector3(MoveHorizontal, 0, MoveVertical);
transform.Translate(Vector3.forward * MoveVertical);
}