I am trying to rotate the character with a delayed rotation something like Paper Mario. i am using this to rotate the player in y axis.
Quaternion newRoatation = Quaternion.identity;
newRoatation = Quaternion.Euler(0f,360f,0f);
transform.rotation = Quaternion.Lerp(transform.rotation, newRoatation, 10f * Time.deltaTime);
when ever it rotates it ends up in y = -28.07
i dont understand it.
This is the full code.
Rigidbody2D rb;
Animator anim;
public bool isGrounded,facingRight,flip,canFlip;
public float charSpeed,jumpHeight,maxSpeed = 7f;
Vector2 direction;
// Start is called before the first frame update
void Start()
{
facingRight = true;
canFlip = true;
anim = GetComponent<Animator>();
rb = gameObject.GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void FixedUpdate()
{
direction = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Horizontal"));
MoveChar(direction.x);
//transform.Translate(Input.GetAxisRaw("Horizontal") * charSpeed * Time.deltaTime, 0f, 0f);
if(Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.D))
{
flip = true;
}
if (flip == true && canFlip == true)
{
Flip();
}
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.W) && isGrounded)
{
rb.velocity = Vector2.up * jumpHeight;
isGrounded = false;
}
}
void MoveChar(float horizontal)
{
rb.AddForce(Vector2.right * horizontal * charSpeed);
anim.SetFloat("magnitude", Mathf.Abs(rb.velocity.x));
if(rb.velocity.x > maxSpeed)
{
rb.velocity = new Vector2(Mathf.Sign(rb.velocity.x) * maxSpeed, rb.velocity.y);
}
}
void Flip()
{
if(facingRight == false)
{
Quaternion newRoatation = Quaternion.identity;
newRoatation = Quaternion.Euler(0f,360f,0f);
transform.rotation = Quaternion.Lerp(transform.rotation, newRoatation, 10f * Time.deltaTime);
float angle = Quaternion.Angle(transform.rotation, newRoatation);
Debug.Log(angle);
if (angle == 0)
{
Debug.Log("flip done");
transform.rotation = Quaternion.Euler(Vector3.zero);
facingRight = true;
flip = false;
}
}
if (facingRight == true)
{
Quaternion newRoatation = Quaternion.Euler(0f, 180f, 0f);
transform.rotation = Quaternion.Lerp(transform.rotation, newRoatation, 10f * Time.deltaTime);
float angle = Quaternion.Angle(transform.rotation, newRoatation);
if (angle == 0)
{
Debug.Log("flip done");
transform.rotation = newRoatation;
facingRight = false;
flip = false;
}
}
}