Categories
Game Creation Mastering Development

How do I replicate my missiles and follow the player the same as the game called “Go Plane”


I am trying to make a clone of https://play.google.com/store/apps/details?id=io.voodoo.goplane1&hl=en
or “Go Plane” and I was wondering how can I follow that kind of missiles where the player can dodge it by moving away from it. Any help? Thanks in Advance! 😀


CODE FOR PLAYER

public float moveSpeed;
Rigidbody2D myBody;
protected Joystick joystick;

void Start()
{
    joystick = FindObjectOfType<Joystick>();
}

// Update is called once per frame
void Update()
{
    myBody = GetComponent<Rigidbody2D>();

    myBody.velocity = new Vector2(joystick.Horizontal * moveSpeed, joystick.Vertical * moveSpeed);
}

CODE FOR MISSILES

public float acceleration = 1.0f;
public float maxSpeed = 5.0f;

public float speed;
public float distance;

private Transform Player;

void Start()
{
    Player = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
}
void Update()
{
    if (Vector3.Distance(transform.position, Player.position) > distance)
    {
        speed += acceleration * Time.deltaTime;

        transform.position = Vector3.MoveTowards(transform.position, Player.position, speed * Time.deltaTime);     

        if (speed > maxSpeed)
            speed = maxSpeed;
    }
}

Leave an answer

Your email address will not be published. Required fields are marked *