A_SpawnActorLine

From ZDoom Wiki
Jump to navigation Jump to search

void A_SpawnActorLine (string classname, Vector3 pointA, Vector3 pointB, double units = 1)

Usage

Spawns actors in a line from pointA to pointB.

Parameters

  • classname: The type of actor to spawn (eg, "ZombieMan")
  • pointA: The point to start spawning actors from
  • pointB: The point to stop spawning actors at
  • units: The number of units between each actor that is spawned

Implementing into your mod

Add the following ZScript function to your actor of choice. This does not need to be repeated for classes which inherit from another already possessing this function.

action void A_SpawnActorLine(string classname, Vector3 pointA, Vector3 pointB, double units = 1)
{
	// get a vector pointing from A to B
	let pointAB = pointB - pointA;

	// get distance
	let dist = pointAB.Length();

	// normalize it
	pointAB /= dist == 0 ? 1 : dist;

	// iterate in units of 'units'
	for (double i = 0; i < dist; i += units)
	{
		// we can now use 'pointA + i * pointAB' to
		// get a position that is 'i' units away from
		// pointA, heading in the direction towards pointB
		let position = pointA + i * pointAB;
		Spawn(classname, position);
	}
}

The function is now ready for use.

Examples

Nuvolachalk.png Note: This article lists no examples. If you make use of this feature in your own project(s) or know of any basic examples that could be shared, please add them. This will make it easier to understand for future authors seeking assistance. Your contributions are greatly appreciated.