calculate different angles in 2d
Hey There!
i am trying to replicate game Missiles! from the playstore.
My Current code works like this.
private void Update()
{
Vector2 joyinput = new Vector2(joystick.Horizontal, joystick.Vertical);
rb.MovePosition(transform.position + (movespeed * transform.up));
float angle = Quaternion.FromToRotation(transform.up, joyinput).eulerAngles.z;
rb.MoveRotation((transform.rotation.eulerAngles).z + turnspeed * angle);
}
This Image describes my problem the best: Soo how would i convert the current angle (left) to the correct angle (right)?
Thanks for any help!
Answer by N-8-D-e-v · Jun 17, 2020 at 05:35 PM
You could accomplish this with if statements, like
if (dir == 0 && underneathCenter)
{
transform.eulerAngles = Vector3.zero
}
or something like that
Yeah your right Didnt think of this if (angle > 0 && angle <= 90) {
}else if(angle > 90 && angle <= 180)
{
angle = angle - 180;
}
else if (angle > 180 && angle <= 270)
{
angle = angle - 180;
}
else if (angle > 270 && angle <= 360)
{
angle = angle - 360;
}
Your answer
Follow this Question
Related Questions
Rotating Movement with Acceleration problem 1 Answer
How to get the angle a 2D character is facing? 1 Answer
I have no Idea why my highscore Script isn't working ... 0 Answers
Rigidbody not able to be linked to object within unity for some reason? 1 Answer
Instantiating Projectiles not working at certain directions?? 2 Answers