Skip to main content
Fixed word order
Source Link

Since you've asked for a solution that involves little coding, I'd suggest using linked prefabs. The idea is to build a "library" of simple maneuvers and then chain them.
Pseudocode below, followed by an explanation:

"Move" class to represent a single maneuver:

public Vector2 velocity;  
public float angularVelocity;  
public float duration;  

void execute(float stepSize, Transform avatar) {  
  //move avatar, e.g. avatar.Translate(avatar.forward * velocity * stepSize);  
  //rotate avatar  
}

"MoveSet" class to represent an enemy's course:

public Vector2 spawnOffset; //optional, but if you need this, best put it here  
public Move[] moves;  
private int currentMove = 0;
private float moveTime;  

bool execute(float stepSize, Transform avatar) {  
  moves[currentMove].execute(stepSize, avatar);  
  moveTime += stepSize;  
  if (moveTime >= moves[currentMove].duration) {  
    currentMove += 1;  
    moveTime = 0;  
    if (currentMove >= moves.Length)  
      return true; //move set finished - repeat set or despawn enemy etc.  
  }  
  return false;  
}  

In your enemy class, add a public MoveSet variable and call

myMoveSet.execute(time.fixedDeltaTime, gameObject.transform)  

from FixedUpdate.

In your Move's and MoveSet's OnDrawGizmosSelected, call execute in a loop with a suitable step size and e.g. a Debug.DrawLine(lastPosition, transform.position) call after each step. Reset position after the loop.

How you'd use this:

  1. Create empty GameObject, add "Move" script. The editor should draw an approximation of the path. Fine tune variables until you're satisfied, then save as prefab.

  2. After you have a few "Move" prefabs, create a GameObject with a "MoveSet" component, drag "Move" prefabs into the array until you're satisfied with the course, then save as prefab as well.

  3. Drag a "MoveSet" onto an enemy or assign at runtime. Spawn an instance of the "MoveSet" prefab before using it.

You'll probably have to expand this a little to suit your project, perhaps apply forces instead to a Rigidbody instead of moving directly, tweaking performance etc, but this should give you an idea of where to start.

Since you've asked for a solution that involves little coding, I'd suggest using linked prefabs. The idea is to build a "library" of simple maneuvers and then chain them.
Pseudocode below, followed by an explanation:

"Move" class to represent a single maneuver:

public Vector2 velocity;  
public float angularVelocity;  
public float duration;  

void execute(float stepSize, Transform avatar) {  
  //move avatar, e.g. avatar.Translate(avatar.forward * velocity * stepSize);  
  //rotate avatar  
}

"MoveSet" class to represent an enemy's course:

public Vector2 spawnOffset; //optional, but if you need this, best put it here  
public Move[] moves;  
private int currentMove = 0;
private float moveTime;  

bool execute(float stepSize, Transform avatar) {  
  moves[currentMove].execute(stepSize, avatar);  
  moveTime += stepSize;  
  if (moveTime >= moves[currentMove].duration) {  
    currentMove += 1;  
    moveTime = 0;  
    if (currentMove >= moves.Length)  
      return true; //move set finished - repeat set or despawn enemy etc.  
  }  
  return false;  
}  

In your enemy class, add a public MoveSet variable and call

myMoveSet.execute(time.fixedDeltaTime, gameObject.transform)  

from FixedUpdate.

In your Move's and MoveSet's OnDrawGizmosSelected, call execute in a loop with a suitable step size and e.g. a Debug.DrawLine(lastPosition, transform.position) call after each step. Reset position after the loop.

How you'd use this:

  1. Create empty GameObject, add "Move" script. The editor should draw an approximation of the path. Fine tune variables until you're satisfied, then save as prefab.

  2. After you have a few "Move" prefabs, create a GameObject with a "MoveSet" component, drag "Move" prefabs into the array until you're satisfied with the course, then save as prefab as well.

  3. Drag a "MoveSet" onto an enemy or assign at runtime. Spawn an instance of the "MoveSet" prefab before using it.

You'll probably have to expand this a little to suit your project, perhaps apply forces instead to a Rigidbody of moving directly, tweaking performance etc, but this should give you an idea of where to start.

Since you've asked for a solution that involves little coding, I'd suggest using linked prefabs. The idea is to build a "library" of simple maneuvers and then chain them.
Pseudocode below, followed by an explanation:

"Move" class to represent a single maneuver:

public Vector2 velocity;  
public float angularVelocity;  
public float duration;  

void execute(float stepSize, Transform avatar) {  
  //move avatar, e.g. avatar.Translate(avatar.forward * velocity * stepSize);  
  //rotate avatar  
}

"MoveSet" class to represent an enemy's course:

public Vector2 spawnOffset; //optional, but if you need this, best put it here  
public Move[] moves;  
private int currentMove = 0;
private float moveTime;  

bool execute(float stepSize, Transform avatar) {  
  moves[currentMove].execute(stepSize, avatar);  
  moveTime += stepSize;  
  if (moveTime >= moves[currentMove].duration) {  
    currentMove += 1;  
    moveTime = 0;  
    if (currentMove >= moves.Length)  
      return true; //move set finished - repeat set or despawn enemy etc.  
  }  
  return false;  
}  

In your enemy class, add a public MoveSet variable and call

myMoveSet.execute(time.fixedDeltaTime, gameObject.transform)  

from FixedUpdate.

In your Move's and MoveSet's OnDrawGizmosSelected, call execute in a loop with a suitable step size and e.g. a Debug.DrawLine(lastPosition, transform.position) call after each step. Reset position after the loop.

How you'd use this:

  1. Create empty GameObject, add "Move" script. The editor should draw an approximation of the path. Fine tune variables until you're satisfied, then save as prefab.

  2. After you have a few "Move" prefabs, create a GameObject with a "MoveSet" component, drag "Move" prefabs into the array until you're satisfied with the course, then save as prefab as well.

  3. Drag a "MoveSet" onto an enemy or assign at runtime. Spawn an instance of the "MoveSet" prefab before using it.

You'll probably have to expand this a little to suit your project, perhaps apply forces to a Rigidbody instead of moving directly, tweaking performance etc, but this should give you an idea of where to start.

added 76 characters in body
Source Link

Since you've asked for a solution that involves little coding, I'd suggest using linked prefabs. The idea is to build a "library" of simple maneuvers and then chain them.
Pseudocode below, followed by an explanation:

"Move" class to represent a single maneuver:

public Vector2 velocity;  
public float angularVelocity;  
public float duration;  
private float lifetime;  

boolvoid execute(float stepSize, Transform avatar) {  
  //move avatar, e.g. avatar.Translate(avatar.forward * velocity * stepSize);  
  //rotate avatar  
  lifetime += stepSize;  
  return lifetime >= duration; //maneuver finished?  
}

"MoveSet" class to represent an enemy's course:

public Vector2 spawnOffset; //optional, but if you need this, best put it here  
public Move[] moves;  
private int currentMove = 0;
private float moveTime;  

bool execute(float stepSize, Transform avatar) {  
  if (moves[currentMove].execute(stepSize, avatar);  
  moveTime += stepSize;  
  if (moveTime >= moves[currentMove].duration) {  
    currentMove += 1;  
    moveTime = 0;  
    if (currentMove >= moves.Length)  
      return true; //move set finished - repeat set or despawn enemy etc.  
  }  
  return false;  
}  

In your enemy class, add a public MoveSet variable and call

myMoveSet.execute(time.fixedDeltaTime, gameObject.transform)  

from FixedUpdate.

In your Move's and MoveSet's OnDrawGizmosSelected, call execute in a loop with a suitable step size and e.g. a Debug.DrawLine(lastPosition, transform.position) call after each step. Reset position after the loop.

The wayHow you'd use this:

  1. Create empty GameObject, add "Move" script. The editor should draw an approximation of the path. Fine tune variables until you're satisfied, then save as prefab.

  2. After you have a few "Move" prefabs, create a GameObject with a "MoveSet" component, drag "Move" prefabs into the array until you're satisfied with the course, then save as prefab as well.

  3. Drag a "MoveSet" onto an enemy or assign at runtime. Spawn an instance of the "MoveSet" prefab before using it.

You'll probably have to expand this a little to suit your project, perhaps apply forces instead to a Rigidbody of moving directly, tweaking performance etc, but this should give you an idea of where to start.

Since you've asked for a solution that involves little coding, I'd suggest using linked prefabs. The idea is to build a "library" of simple maneuvers and then chain them.
Pseudocode below, followed by an explanation:

"Move" class to represent a single maneuver:

public Vector2 velocity;  
public float angularVelocity;  
public float duration;  
private float lifetime;  

bool execute(float stepSize, Transform avatar) {  
  //move avatar, e.g. avatar.Translate(avatar.forward * velocity * stepSize);  
  //rotate avatar  
  lifetime += stepSize;  
  return lifetime >= duration; //maneuver finished?  
}

"MoveSet" class to represent an enemy's course:

public Vector2 spawnOffset; //optional, but if you need this, best put it here  
public Move[] moves;  
private int currentMove = 0;

bool execute(float stepSize, Transform avatar) {  
  if (moves[currentMove].execute(stepSize, avatar)) {  
    currentMove += 1;  
    if (currentMove >= moves.Length)  
      return true; //move set finished - repeat set or despawn enemy etc.  
  }  
  return false;  
}  

In your enemy class, add a public MoveSet variable and call

myMoveSet.execute(time.fixedDeltaTime, gameObject.transform)  

from FixedUpdate.

In your Move's and MoveSet's OnDrawGizmosSelected, call execute in a loop with a suitable step size and e.g. a Debug.DrawLine(lastPosition, transform.position) call after each step. Reset position after the loop.

The way you'd use this:

  1. Create empty GameObject, add "Move" script. The editor should draw an approximation of the path. Fine tune variables until you're satisfied, then save as prefab.

  2. After you have a few "Move" prefabs, create a GameObject with a "MoveSet" component, drag "Move" prefabs into the array until you're satisfied with the course, then save as prefab as well.

  3. Drag a "MoveSet" onto an enemy or assign at runtime

You'll probably have to expand this a little to suit your project, perhaps apply forces instead to a Rigidbody of moving directly, tweaking performance etc, but this should give you an idea of where to start.

Since you've asked for a solution that involves little coding, I'd suggest using linked prefabs. The idea is to build a "library" of simple maneuvers and then chain them.
Pseudocode below, followed by an explanation:

"Move" class to represent a single maneuver:

public Vector2 velocity;  
public float angularVelocity;  
public float duration;  

void execute(float stepSize, Transform avatar) {  
  //move avatar, e.g. avatar.Translate(avatar.forward * velocity * stepSize);  
  //rotate avatar  
}

"MoveSet" class to represent an enemy's course:

public Vector2 spawnOffset; //optional, but if you need this, best put it here  
public Move[] moves;  
private int currentMove = 0;
private float moveTime;  

bool execute(float stepSize, Transform avatar) {  
  moves[currentMove].execute(stepSize, avatar);  
  moveTime += stepSize;  
  if (moveTime >= moves[currentMove].duration) {  
    currentMove += 1;  
    moveTime = 0;  
    if (currentMove >= moves.Length)  
      return true; //move set finished - repeat set or despawn enemy etc.  
  }  
  return false;  
}  

In your enemy class, add a public MoveSet variable and call

myMoveSet.execute(time.fixedDeltaTime, gameObject.transform)  

from FixedUpdate.

In your Move's and MoveSet's OnDrawGizmosSelected, call execute in a loop with a suitable step size and e.g. a Debug.DrawLine(lastPosition, transform.position) call after each step. Reset position after the loop.

How you'd use this:

  1. Create empty GameObject, add "Move" script. The editor should draw an approximation of the path. Fine tune variables until you're satisfied, then save as prefab.

  2. After you have a few "Move" prefabs, create a GameObject with a "MoveSet" component, drag "Move" prefabs into the array until you're satisfied with the course, then save as prefab as well.

  3. Drag a "MoveSet" onto an enemy or assign at runtime. Spawn an instance of the "MoveSet" prefab before using it.

You'll probably have to expand this a little to suit your project, perhaps apply forces instead to a Rigidbody of moving directly, tweaking performance etc, but this should give you an idea of where to start.

Source Link

Since you've asked for a solution that involves little coding, I'd suggest using linked prefabs. The idea is to build a "library" of simple maneuvers and then chain them.
Pseudocode below, followed by an explanation:

"Move" class to represent a single maneuver:

public Vector2 velocity;  
public float angularVelocity;  
public float duration;  
private float lifetime;  

bool execute(float stepSize, Transform avatar) {  
  //move avatar, e.g. avatar.Translate(avatar.forward * velocity * stepSize);  
  //rotate avatar  
  lifetime += stepSize;  
  return lifetime >= duration; //maneuver finished?  
}

"MoveSet" class to represent an enemy's course:

public Vector2 spawnOffset; //optional, but if you need this, best put it here  
public Move[] moves;  
private int currentMove = 0;

bool execute(float stepSize, Transform avatar) {  
  if (moves[currentMove].execute(stepSize, avatar)) {  
    currentMove += 1;  
    if (currentMove >= moves.Length)  
      return true; //move set finished - repeat set or despawn enemy etc.  
  }  
  return false;  
}  

In your enemy class, add a public MoveSet variable and call

myMoveSet.execute(time.fixedDeltaTime, gameObject.transform)  

from FixedUpdate.

In your Move's and MoveSet's OnDrawGizmosSelected, call execute in a loop with a suitable step size and e.g. a Debug.DrawLine(lastPosition, transform.position) call after each step. Reset position after the loop.

The way you'd use this:

  1. Create empty GameObject, add "Move" script. The editor should draw an approximation of the path. Fine tune variables until you're satisfied, then save as prefab.

  2. After you have a few "Move" prefabs, create a GameObject with a "MoveSet" component, drag "Move" prefabs into the array until you're satisfied with the course, then save as prefab as well.

  3. Drag a "MoveSet" onto an enemy or assign at runtime

You'll probably have to expand this a little to suit your project, perhaps apply forces instead to a Rigidbody of moving directly, tweaking performance etc, but this should give you an idea of where to start.