collinhover / impactplusplus

Impact++ is a collection of additions to ImpactJS with full featured physics, dynamic lighting, UI, abilities, and more.
http://collinhover.github.com/impactplusplus
MIT License
276 stars 58 forks source link

spawnAndMoveTo Question #116

Closed racingcow closed 10 years ago

racingcow commented 10 years ago

Hello,

I have created a generic SpawnerCharacterLibraried module, very similar to the one used in the supercollider demo, to use to generically create various spawners in Weltmeister. I have it set up to spawn at a void entity at a location underneath it. Everything works fine, and the spawner creates entities of the specified type at the void entity as it should.

Now, after they spawn, I want the entities walk from the spawn point to another void entity. Here is a screenshot of what I have in the editor...

image

...and here are the properties set on the spawner1 spawner in the editor...

{
    name: spawner1,
    spawnTarget.1: spawnpoint1,
    spawnTarget.2: defendpoint,
    spawningEntity: EntityBeforeLight,
    spawnCountMax: 5,
    duration: 20,
    animSheetPath: enemy-factory.png,
    spawnAndMoveTo: true,
    spawnAtFirstTarget: true
}

The entities all spawn, but don't move to the second target afterward. When debugging, I noticed that they start wandering immediately, which seemed to prevent them from moving to the second target (canWanderX / canWanderY were set on the spawned entities). To try and override that, I added the following settings to spawner1...

{
    spawnSettings: {
        canWanderX: false,
        canWanderY: false
    }
}

Still no luck. The entities would spawn at the first target, but then stay there. After stepping through the code some more, I verified that the creature was no longer trying to wander, and spawner.spawnNext is definitely calling moveTo and passing in the entities in the targets map. entity.moveTo sets the entity's movingTo property to the first target in the map, and returns true, making the entity move to it.

After that, however, it seems to stop without trying to move to the second target, and I'm not sure why.

Is there something I need to do differently to get the entity to move the second target after being spawned?

Thanks in advance for any help that you might be able to give and, as always, thanks for the great library!

collinhover commented 10 years ago

In the spawnSettings, set the preyName property to the name of the entity you want the creatures to move to after spawning. Make sure the creatures either have infinite reaction and search distance or they spawn within their search distance range to the final move to target. Creatures manage their own movement via wander, prey, and predator, so trying to use move to directly doesn't work so well (yet). Spawners also don't account for creatures in the spawn and move to setup (yet), as it was originally intended for non dynamic entities when I added it.

racingcow commented 10 years ago

Setting the preyName works great. They now move to the entity to which it is set. Thanks, @collinhover!