- Home /
How to make sprites in SideScroller move in smooth curves
I am learning Unity3d with a practice project (a Moon Patrol Clone basically) I have enemies that move in the level using the below code. What I am trying to figure out is what the best way would be to make them move more naturally along curves.
 public class EnemyFighterController : MonoBehaviour
 {
 
     public float Speed;
     public float ExitSpeed; // Enemies move faster to last waypoint as they exit
     public List<Vector3> Waypoints;
     private Vector3 nextWaypoint;
 
     void Start()
     {
         getNextWaypoint();
     }
     // Get the next waypoint from the list and then remove it
     private void getNextWaypoint()
     {
         nextWaypoint = Waypoints[0];
         Waypoints.RemoveAt(0);
         if (Waypoints.Count == 0)
             Speed = ExitSpeed;
     }
 
     void Update()
     {
       transform.position = Vector3.MoveTowards(transform.position, nextWaypoint,
                                                 Speed * Time.deltaTime);
          // Once the enemy is close to the target waypoint get the next one 
          // if there is one otherwise deactivate the enemy
         if (Vector3.Distance(transform.position, nextWaypoint) < 0.1f)
         {
             if (Waypoints.Count > 0)
                 getNextWaypoint();
             else
                 gameObject.SetActive(false);
         }
     }
 }
               Comment
              
 
               
              You might want to take a look at methods discussed in these questions:
Thanks, I will look at those. By the way I meant to add to this that I am looking for documentation and tutorials, not code or an exact solution. The project is, after all, a learning project!
Your answer
 
 
             Follow this Question
Related Questions
Making a bubble level (not a game but work tool) 1 Answer
Sprite flip movement script not working! HELP! 0 Answers
Sprite is not shown moving 1 Answer
Question on Sprite and Movement 0 Answers
Character doesn't jump repeatedly 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                