i have 3D player with 2D movement (something like 2.5D) i want to rotate the player on direction change.
Here is the problem im facing
- i have to make the player speed to zero (so player cant move when its in rotating proses) and turn it back when finished
- normal rotation “i know sounds stupid”
=========================================================
take look at my script
public class Lucy_Movement : MonoBehaviour
{
[SerializeField] private Animator Anim;
[SerializeField] private Rigidbody2D rb;
[SerializeField] private AudioSource FootStep;
[SerializeField] private Joy_Stick joystick;
[Header("Player Speed")] public float speed = 2;
[Header("Player Direction")] public float horizontal;
public bool IsFacingRight = true;
private float rotate = 90f;
private void Start()
{
rb = GetComponent<Rigidbody2D>();
Anim = GetComponent<Animator>();
joystick = GameObject.Find("JoyStick").GetComponent<Joy_Stick>();
FootStep = GetComponent<AudioSource>();
}
private void FixedUpdate()
{
// player rotation
rotate = transform.rotation.y;
// get the joystick value
horizontal = joystick.joyStick.value;
// player movement based on physics
rb.AddForce(new Vector2(horizontal * speed, 0), ForceMode2D.Force);
// rotate player on changing direction
#region
if (IsFacingRight)
{
if (rotate < 90f || rotate > 90f)
{
speed = 0;
transform.Rotate(0, 10, 0);
}
speed = 2;
}
if (!IsFacingRight)
{
if (rotate < -90f || rotate > -90f)
{
speed = 0;
transform.Rotate(0, -10, 0);
}
speed = 2;
}
#endregion
// animation controller
#region
if (horizontal == 0)
{
// idle
Anim.Play("idle|Idle");
}
if (horizontal > 0.0f)
{
// walk right
Anim.Play("idle|Walk");
}
if (horizontal < 0.0f)
{
// walk left
Anim.Play("idle|Walk");
}
if (speed > 2.0f)
{
// run
Anim.Play("idle|Run");
}
#endregion
// Check If Player Facing Left/Right "RETURN = TRUE/FALSE"
#region
if (horizontal > 0.0f)
{
IsFacingRight = true;
}
if (horizontal < 0.0f)
{
IsFacingRight = false;
}
#endregion
}
}
the rotation script is wrong and make the player spin
any idea to fix this ?
im stucked here the hole day ![]()
i want to stop the rotation at 90 and -90 degrees but its keep rotating
– jwadgri