0
\$\begingroup\$
    void Start()
{
    target = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
    Speed = Mathf.Lerp(speedScaling.x, speedScaling.y, Difficulty.GetDifficultyPercentage());
    visibleThreshold = -Camera.main.orthographicSize - transform.localScale.y;
}

// Update is called once per frame
void Update()
{
    FollowTarget();
    transform.Translate(Vector3.down * Speed * Time.deltaTime);

    if(transform.position.y < visibleThreshold)
    {
        Destroy(gameObject);
    }
}

void FollowTarget()
{
    transform.position = Vector2.MoveTowards(transform.position, target.position, Speed * Time.deltaTime);
}

I managed to make this projectile follow the target but not what i wanted to

\$\endgroup\$
1
  • \$\begingroup\$ Can you show us some images of what you're trying to achieve? Or give us an example of a game/simulation where this is done? Do you want the gameobjects to have a view frustum and they can only track the players if they can "see" them? Or just stop tracking once it reaches the target? Currently your script makes it so the gameobject will always EVENTUALLY reach the target, is this what you want? \$\endgroup\$
    – Charly
    Jan 2 at 17:38

0

You must log in to answer this question.

Browse other questions tagged .