In the linked gif, when I move the right-joystick left, it first fires a bullet to the right (original position) before following the rotation of the player. I want it to fire once the rotation has been complete.
This is the script that handles the rotating the player gameobject:
{
Vector2 lookInput = playerInput.Player.Look.ReadValue<Vector2>();
rotate = Vector3.zero;
rotate.x = lookInput.x;
rotate.y = lookInput.y;
// Checks if right joystick has moved
if (rotate != Vector3.zero)
{
// Handles rotation
rotate.Normalize();
if (rotate.x >= 0 && rotate.y >= -1 && rotate.y < 0)
{
angle = Vector2.SignedAngle(Vector2.down, rotate);
myRigidBody.MoveRotation(Quaternion.Euler(0, 0, angle));
}
else if (rotate.x >= 0 && rotate.y >= 0 && rotate.y < 1)
{
angle = Vector2.SignedAngle(Vector2.right, rotate) + 90;
myRigidBody.MoveRotation(Quaternion.Euler(0, 0, angle));
}
else if (rotate.x <= 0 && rotate.y > 0 && rotate.y <= 1)
{
angle = Vector2.SignedAngle(Vector2.up, rotate) + 180;
myRigidBody.MoveRotation(Quaternion.Euler(0, 0, angle));
}
else
{
angle = Vector2.SignedAngle(Vector2.left, rotate) + 270;
myRigidBody.MoveRotation(Quaternion.Euler(0, 0, angle));
}
// Fires Bullet based on fireRate
if (Time.time > nextFire)
{
Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
nextFire = Time.time + 1 / fireRate;
}
}
}
The start function of my bullet script:
{
playerRigidBody.velocity = transform.up * speed * -1;
StartCoroutine(DestroyCo());
}