// ww_invisible_fence
/*
This is the On Enter script for a Trigger blueprint that
causes a non-controlled animal to 'back off' upon entry.
It can be used, for example, to cover an opening to a
fenced-in area where the livestock have been given
'X2_L_SPAWN_USE_AMBIENT = 1' variable settings.
*/
// RJH 30jun13
void main()
{
object oTarget = GetEnteringObject();
if ( ! GetIsObjectValid( oTarget ) )
return; // Invalid object
// Check if the creature is of type Animal
if ( GetRacialType( oTarget ) != RACIAL_TYPE_ANIMAL )
return;
// Check if creature is player-controlled
object oControl = GetControlledCharacter( oTarget );
if ( oControl != OBJECT_INVALID )
return;
// Get current creature location information
location locCreature = GetLocation( oTarget );
// Compute a 'back off' vector
float facAway = GetFacingFromLocation( locCreature ) + 180.0f;
vector vAwayNorm = VectorNormalize( AngleToVector( facAway ) );
float fScale = 0.5;
vector vAway = Vector( fScale * vAwayNorm.x, fScale * vAwayNorm.y, fScale * vAwayNorm.z );
vector vPos = GetPositionFromLocation( locCreature );
// Stop the current movement
AssignCommand( oTarget, ClearAllActions() );
// Compute the new destination
object oArea = GetAreaFromLocation( locCreature );
location locTurnAway = Location( oArea, vPos + vAway, facAway );
location locSafeTurnAway = CalcSafeLocation( oTarget, locTurnAway, 0.4f, TRUE, FALSE );
// Order creature away after a brief pause
AssignCommand( oTarget, ActionWait( 0.2f ) );
DelayCommand( 0.2f, AssignCommand( oTarget, ActionMoveToLocation( locSafeTurnAway ) ) );
}
Modifié par rjshae, 23 octobre 2013 - 03:34 .





Retour en haut







