I'm trying to create a script which makes animals herd together, which uses the heartbeat element to check distance from another creature, and if too far away, moves them together.
The problem I'm having is that whilst this works fine for creatures that are placed directly into the mod; if the creatures are created via an encounter spawn, it doesn't work. The script itself does fire and the checks etc all fire correctly (tested with a speakstring), but the creature's don't actually move. "sCreatureTag" is displayed as part of the debug text, and it's the same whether the creature is placed directly or spawned.
Any ideas? Bit stumped.
This is the code. This was added to a replacement version of the default NW_C2_DEFAULT1 script that the creature has set to it's OnHeartbeat.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
object oMe = OBJECT_SELF;
string sCreatureTag = GetTag(oMe);
// get the nearest creature in the area with the same tag as itself (ie one of the same creature type)
object oNearbyCreature = GetNearestObjectByTag(sCreatureTag, oMe, 1);
// if there is another creature with the same tag in the area, and it's more than 8 metres away, run towards it
if ( GetIsObjectValid(oNearbyCreature) && GetDistanceToObject(oNearbyCreature) > 8.0 )
{
ActionForceMoveToObject(oNearbyCreature, TRUE, 5.0, 30.0);
SpeakString(sCreatureTag + " is seeking the herd", TALKVOLUME_TALK);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Heartbeat script on spawned creatures
Débuté par
Aradan Kir
, août 16 2011 02:48
#1
Posté 16 août 2011 - 02:48
#2
Posté 16 août 2011 - 03:13
Try ClearAllActions before your Force Move. THe creature could be doing something like RandomWalk. Never getting to your move action in the action Que.
#3
Posté 16 août 2011 - 06:32
#4
Posté 16 août 2011 - 07:46
Lightfoot8 wrote...
Try ClearAllActions before your Force Move. THe creature could be doing something like RandomWalk. Never getting to your move action in the action Que.
Yes, this fixed it! Thanks so much!!
Also, thanks for the Flocking script - I'll check that out; but this was mostly about me getting my head around scripting, rather than necessarily needing an actual herding system working.
Thanks guys - much appreciated!





Retour en haut






