using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MissilePathing : MonoBehaviour
{
List<Transform> waypointsMissile;
int waypointIndex = 0;
float moveSpeed;
Vector3 startingPosition;
void Start()
{
startingPosition = transform.position;
waypointsMissile = FindObjectOfType<Player>().GetWaypoints();
}
void Update()
{
Move();
}
private void Move()
{//qui è dove una volta nato conlo faccio muovere
if (waypointIndex <= waypointsMissile.Count - 1)
{
var targetPosition = waypointsMissile[waypointIndex].transform.position + startingPosition; ; //posizione target
var movementThisFrame = 2f * Time.deltaTime; //velocità con la quale si muoverà
transform.position = Vector2.MoveTowards //funzione per muoversi VERSO una posizione target
(transform.position,
targetPosition,
movementThisFrame);
if (transform.position == targetPosition)
{
waypointIndex++;
}
} //se sono all'ultimo
}
}
So this is the current right code, something changed, now when i move and shoot the trajectory is somehow linked on where i am but it is still slightly wrong, like now it’s like every waypoint is moved down/right from the player
at least it is linked to where i am now