How do i have my player in 2d go up regardless of the players rotation
Im making a 2d top down space shooter game, and i want there to be drag for more fluent movement however when i use addforce it adds the force to my transforms axis. For instance when my player is looking at my mouse bellow it, "up" will make the player go down relative to the world. I want the player to rotate to the mouse while having the movement keys stay the same no matter the rotation. This is the script im using before that, that allowed me to make the player go up regardless of the rotation however the movement stops or changes at the click of a button while i want there to be some form of momentum.
public class RotatePlayerTowards : MonoBehaviour { public Rigidbody2D rb;
public Camera cam;
public float Speed = 20.0f;
Vector2 mousePos;
Vector2 movement;
void Update()
{
movement.x = Input.GetAxisRaw("Horizontal");
movement.y = Input.GetAxisRaw("Vertical");
mousePos = cam.ScreenToWorldPoint(Input.mousePosition);
}
void FixedUpdate()
{
rb.MovePosition(rb.position + movement * Speed * Time.fixedDeltaTime);
Vector2 lookDir = mousePos - rb.position;
float angle = Mathf.Atan2(lookDir.y, lookDir.x) * Mathf.Rad2Deg - 90f;
rb.rotation = angle;
}
Your answer
Follow this Question
Related Questions
How to make player go forward when he is rotated? 0 Answers
Rotate player 0 Answers