Hey is there a way that I can have 5 objects surround a player and form a pentagon shape?
I think you’re referring to objects following the player. If so then why not make them child objects of the player?
well, you know that a pentagram is made up of 5 points around a circle at 72 degrees.
use that knowledge + trig to calculate the x/z positions.
Try this.
public class Test : MonoBehaviour
{
public GameObject target;
public GameObject cloneFrom;
public int amount;
public float radius;
void Start()
{
Surround (target, cloneFrom, amount, radius);
}
// this function replicate the object surrounding the target
public void Surround(GameObject target, GameObject prefab, int amount, float radius)
{
float angle = 360f / amount;
for (int i = 0; i < amount; i++)
{
GameObject go = Instantiate (prefab) as GameObject;
go.transform.Rotate (Vector3.up, angle*i);
go.transform.position = target.transform.position - (go.transform.forward * radius);
// OR go.GetComponent<NavMeshAgent>().Warp(target.transform.position-(go.transform.forward*radius));
}
}
}
2 Likes