(2D) face movement direction
Hello, I am very new to Unity, and im having a lot of trouble with rotations. I managed to align my player to rotate accordingly alongside slopes(tho i still have to find a way to limit that effect to stop him from going upside down) but now im having trouble with flipping my character to face the movement direction. I already managed to do that in an earlier script but that method seems to cause some trouble now as my player either doesnt flip at all or only for a split second. I am guessing that my new rotation script for handling slopes and my flipping script are interfering with each other.
void FixedUpdate()
{
myCollider.Cast(-Vector3.up,contactFilter,contactPoints ,myCollider.bounds.extents.y + 0.1f, true);
for(int i = 0; i < contactPoints.Length; i++)
{
var angle = Mathf.Atan2(contactPoints[i].normal.x,contactPoints[i].normal.y) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle, -Vector3.forward);
}
if(isGrounded == false)
{
Vector3 eulerRotation = transform.rotation.eulerAngles;
transform.rotation = Quaternion.Euler(eulerRotation.x, eulerRotation.y, 0);
}
if((xMov < 0 && facingRight) || (xMov > 0 && !facingRight))
{
facingRight = !facingRight;
transform.Rotate(new Vector3(0, 180, 0));
}
Raycast = Physics2D.Raycast(transform.position, -Vector2.up, 0.5f);
if(Raycast.collider != null)
{
isGrounded = true;
}
else if(Raycast.collider == null)
{
isGrounded = false;
}
if(jumpInput == true && isGrounded)
{
rb.AddForce(new Vector2(0, inventory.CurrentPlayerClass.jumpForce), ForceMode2D.Impulse);
jumpInput = false;
}
rb.AddForce(new Vector2(xMov * inventory.CurrentPlayerClass.movementSpeed, 0), ForceMode2D.Force);
}
If you have any comments or any advice on any of the code especially on the problem i stated would be awesome. I started coding like 2-3 months ago and want to learn as much as i can.
Your answer
![](https://koobas.hobune.stream/wayback/20220613030222im_/https://answers.unity.com/themes/thub/images/avi.jpg)