Unit Pathing

Discussion in 'How Can I...?' started by Gretto, Jun 10, 2019.

  1. Gretto

    Gretto Boxer

    Joined:
    Jun 10, 2019
    Messages:
    3
    Likes Received:
    0
    Hi, I am trying to create a tower defense type game. I am trying to get my "bullets" to target a tower. What is the best way to do this.



    We tried to modify the "Move" code with the following:

    let target = this.scene().find(this.attribute('Target'));

    let targetpos = target[0].position();

    let attackvector = targetpos - pos;

    let unitvector = attackvector / Math.sqrt(attackvector.x*attackvector.x + attackvector.y*attackvector.y + attackvector.z*attackvector.z);

    _speed = unitvector;



    but it did not seem to work. Are we able to use the Java Script Math library or is there a better way to calculate the vector. Thanks for your help.
     
  2. PunkPuffin

    PunkPuffin Avid Boxer

    Joined:
    Sep 27, 2018
    Messages:
    285
    Likes Received:
    195
    rjp996tt likes this.

Share This Page