Experts,
In my game, Once the game is over, my intention is to let the predators surround the player and rotate around the player. In order to achieve the same, in the script attached to the Predators, I move the Predators closer to the player ( using MoveTowards) and once they reach a point close enough ( Temp in below code) , I want these Predators to circle around the player ( I am using rotatearound). What I am seeing is that the predator does reach the point Temp(look into the below code) but after that it rotates around itself and not around the Player. But If I don’t move to Temp and instead just use rotatearound, Predator seems to rotate around the Player as expected.
What am I doing wrong ?
code :
private void Update()
{
if (GameManager.instance.GameOver)
{
Vector3 Pos = Player.transform.position;
Vector3 Temp = Pos;
Temp.x = Pos.x + 10;
Temp.y = Pos.y + 3;
Temp.z = Pos.z - 10;
if (Vector3.Distance(Temp, transform.position) > 0)
{
Vector3 NextPos = Vector3.MoveTowards(transform.position, Temp, Speed * Time.deltaTime);
GetComponent<Rigidbody>().MovePosition(NextPos);
} else
{
transform.RotateAround(Pos, Vector3.up, Speed * Time.deltaTime);
AudioManagerScript.PlaySound("WhaleSound");
}
}
}