Search Unity

Tower Defense Waypoint

Discussion in 'Scripting' started by Qhailashnikov, Apr 20, 2019.

  1. Qhailashnikov

    Qhailashnikov

    Joined:
    Feb 26, 2018
    Posts:
    33
    Hey, I'm currently working on a Tower Defense Game and used Brackey's Tutorials and after follow all of the tutorials, I mod the codes adding some simple feature on the turrets and it went pretty well.

    But the problem is.. for the Enemy Waypoint.. the enemy moves from point A to point B just like what I wanted to be but the only thing that I couldn't figure out is that the enemy moves but not rotating or facing left or right. I tried to rotate the waypoint object itself but nothings changed so here is the code

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class Waypoints : MonoBehaviour {
    4.  
    5.     public static Transform[] points;
    6.  
    7.     void Awake()
    8.     {
    9.         points = new Transform[transform.childCount];
    10.  
    11.         for (int i = 0; i < points.Length; i++)
    12.         {
    13.             points[i] = transform.GetChild(i);
    14.         }
    15.            
    16.     }
    17. }
    18.  
    I know that I need to add "rotation' but I unable to figure out how to implement it.

    Thanks in advanced.
    Let me know if you need more detail about the issue
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    You probably just need transform.LookAt() on your monster object to look at the target waypoint. Or Quaternion.LookRotation() and Quaternion.RotateTowards() if you want it to happen over time.