Hello
I am trying to have object follow another objectg but keep a certain distance and it should stay above ground as it is a drone thats follows a player.
Right now it just comes all the way into the player and keeps pushing him.
It also penetrates the ground, while i want him to stay above ground
public class followPlayerDrone : MonoBehaviour
{
public Transform Player;
public float speed;
public RangeSensor sensor;
public Vector3 offset;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
var detected = sensor.GetNearest();
if(detected !=null)
{
followPlayer();
}
}
public void followPlayer()
{
transform.LookAt(Player.transform);
transform.position += transform.forward * speed * Time.deltaTime;
/* if((transform.position - Player.transform.position).magnitude < 2f)
{
transform.position = this.transform.position;
}*/
}
public void moveTowards()
{
transform.position = Vector3.MoveTowards(transform.position, Player.position, 250 * Time.deltaTime);
}
}