Friday, December 2

Unrealscript Overview Part Six : Actor

We don't actually place bubbles in the world. We use an object placed in the level as a point to spawn bubbles from, particle - system style. BubbleSpawner is this object. Note that it is marked as a placable so that it can be placed in the editor. The variables qualified by the (Bubble) suffix in their declaration appear as editiable properties in-game. This is an important mechanism to allow designers and artists to tweak the game without programmer input, letting you get on with core logic implementation.



In PostBeginPlay we vary the spawnCounter a bit, to be sure that mutliple emitters aren't in phase. Tick() just counts down using delta time, waiting until the time calsle to spawn a bubble. When it comes, the Spawn() function is called to randomly create a new BubblePawn somewhere randomly around the general vicinity of the spawner. That's all it takes to dynamically create a new in-world actor - the Pawn itself should take care of spawning it's controller.


class BubbleSpawner extends Actor placeable;

var(Bubble) float spawnRange;
var float spawnCountDown;
var(Bubble) float spawnInterval;

event PostBeginPlay()
{
spawnCountDown = spawnInterval * 2.5;
super.PostBeginPlay();
SetHidden(True);
}

event Tick(float DeltaTime)
{
local Vector SpawnLocation;
spawnCountDown -= DeltaTime;
if (spawnCountDown < 0)
{
SpawnLocation = self.Location;
SpawnLocation.X += -spawnRange + FRand() * (spawnRange * 2.0);
SpawnLocation.Y += -spawnRange + FRand() * (spawnRange * 2.0);
spawnCountDown = spawnInterval;
Spawn(class'LavaLamp.BubblePawn', Self,, SpawnLocation );
}
}

defaultproperties
{
spawnInterval = 0.75
spawnRange = 64.0
}

No comments: