My player is not rotating upwards when it moves upwards. Any advice?

I’m making a 2D, top-down stealth game. I’m having trouble with my player rotating up wards when it is moving upwards, but it does rotate towards all the other directions when it is moving towards them. I’ve never encountered a problem like this before, and none of my friends that i’m working with to solve this haven’t been of much help.

`using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;

public class CompletePlayerController : MonoBehaviour {

public Rigidbody2D rb;

float constantSpeed = 5f;

float sprintSpeed = 10f;

private bool a1 = Input.GetKeyUp("UpArrow");

private bool a2 = Input.GetKeyUp("DownArrow");

private bool a3 = Input.GetKeyUp("RightArrow");

private bool a4 = Input.GetKeyUp("LeftArrow");

private bool A = Input.GetKeyUp("A");

private bool WK = Input.GetKeyUp("W");

private bool S = Input.GetKeyUp("S");

private bool  D = Input.GetKeyUp("D");

Vector3 prevpos;

Vector3 curpos;

void Awake() {

	// prevpos is the postion of the gameobject in the previous frame
	prevpos = transform.position;
}

void FixedUpdate()
{
	Rigidbody2D rb = GetComponent<Rigidbody2D>();	
	

	//curpos is the current position of the gameobject
	Vector3 curpos= (transform.position - prevpos);

	// rv stands for rotation value
	float rv = Mathf.Atan2(curpos.x, curpos.y) * Mathf.Rad2Deg;

		rv = 360 - rv;

	Quaternion p = Quaternion.identity;

	p.eulerAngles = new Vector3 (0, 0, 0);	

	Quaternion q = Quaternion.identity;

	q.eulerAngles = new Vector3 (0, 0, rv);

	if (a1 && a2 && a3 && a4 && A && WK && S && D){

		transform.rotation = p;

	} else if(rv != 0 && rv != 360)
		
	transform.rotation = q;

	prevpos = transform.position;

	float moveHorizontal = Input.GetAxisRaw ("Horizontal");

	float moveVertical = Input.GetAxisRaw ("Vertical");

	Vector2 movement = new Vector2 (moveHorizontal, moveVertical);    

	if (Input.GetKey ("space"))
	
		rb.velocity = sprintSpeed * movement;

	else
	
		rb.velocity = constantSpeed * movement;
}

}`

“upwards” (y+, increase on the y axis) is “euler angle z with value 0” (OR 360, OR anything that gives 0 when modulo-d by 360).
therefore your

else if(rv != 0 && rv != 360) transform.rotation = q;

will be skipped for upwards (eulerAngles = Vector3(0, 0, rv ==0) direction.

also, interesting thing with the keypress bools being

bool a1 = Input.GetKeyUp();

defined in class head… wouldn’t expect it to work, as afaik, assignment at declaration happens only once and bools are byval, not byref, so… I’d say you’re missing these assignments in your update… but if it works for you like this, why not… your problem and solution are already described in the first part of my comment :wink: