Page 1 of 1

Pawn Problem

Posted: Thu Apr 03, 2008 5:27 am
by SSFlame
hey, the problem i have is when my pawn is rotating,attacking and when it is moving towards me it plays the default pose instead of the animations and also when it dies it just stands their instead of playing the animation could you help me here is my script

{

// Monster Melee Attack

// Definitions used to customize monster

GROUP [Generic] // name of monster group
BOXWIDTH [60] // width and depth of bounding box
HOSTILEPLAYER [true] // hostile to player
HOSTILEDIFFERENT [false] // hostile to different Pawn group
HOSTILESAME [false] // hostile to same Pawn group
HEALTHATTRIBUTE [health] // name of health attribute
HEALTH [50] // initial amount of health
SIGHTDIST [450] // max distance monster can see at idle
ALERTSIGHTDIST [600] // max distance monster can see when alert
FOV [180] // field of view in degrees
YAWSPEED [120] // speed of rotation in deg/sec
DAMAGEATTRIBUTE [health] // attribute damaged by attack
ALERTTRIGGER [Alert] // triggername used to go to alert mode

// Animations and variables associated with them

STAND [Idle] // idle animation
TURNL [TurnL] // turn left animation
TURNR [TurnR] // turn right animation

PAIN [Pain1] // pain animations
PAIN1 [Pain2]
PAIN2 [Pain3]
PAIN3 [Pain4]
PAINPERCENT [50] // percentage of time pain is shown

DIE [Die1] // dying animations
DIE1 [Die2]
DIE2 [Die3]
DIE3 [Die3]
DIEHOLD [15] // time corpse still appears
DIEFADE [10] // fadeout time of corpse

RUN [Run] // running animation
RUNSPEED [120] // average run speed

MELEEATTACK [Attack] // melee attacking animation
MELEERANGE [90] // max distance to start melee attack
MINMELEEDAMAGE [25] // minimum amount of damage per melee attack
MAXMELEEDAMAGE [30] // maximum amount of damage per melee attack
MELEEDELAY [2] // number of seconds between melee damages

LOSTTIME [15] // time to search for enemy before giving up
POINTRADIUS [20] // radius from point when considered at point


// local variables - do not change

RUNFUNC [monster_run_start] // monster run to attack function
MELEEFUNC [monster_melee_start] // monster melee function
LOSTFUNC [monster_lost_target_start] // monster lost target function

AS_NONE [0]
AS_MELEE [2]
AS_STRAIGHT [3]
melee_time [0]
lost_time [0]
back_up [false]
back_time [0]
left_time [0]
back_flag [false]
attack_state [0]

// spawn pawn and do setup work

Spawn[ ()
{
Console(true);
BoxWidth(BOXWIDTH); // set bounding box width/depth
AttributeOrder(HEALTHATTRIBUTE, HEALTH, "Death"); // give monster health
HostilePlayer(HOSTILEPLAYER); // set who monster is hostile to
HostileSame(HOSTILESAME);
HostileDifferent(HOSTILEDIFFERENT);
SetFOV(FOV); // set field of view
SetGroup(GROUP); // assign a group to belong to
FindTargetOrder(SIGHTDIST, "FoundTarget", DAMAGEATTRIBUTE); // seen a target to chase
AddPainOrder("IdlePain", 100); // show pain and trigger alert
AddTriggerOrder("IdleToAlert", ALERTTRIGGER, 0); // go to alert when triggered
NewOrder("Idle");
} ]

// idle in place waiting for something to happen

Idle[ ()
{
PlayAnimation(STAND, true, ""); // stand at idle
if(random(1,10)>6) // turn side to side sometimes
{
if(random(1,10)>5) // turn to left 90 degrees and turn back
{
Rotate(TURNL, 102, 0, 90, 0, "");
PlayAnimation(STAND, true, "");
Rotate(TURNR, 108, 0, -90, 0, "");
}
else // turn to right 90 degrees and turn back
{
Rotate(TURNR, 108, 0, -90, 0, "");
PlayAnimation(STAND, true, "");
Rotate(TURNL, 102, 0, 90, 0, "");
}
}
RestartOrder();
} ]

// show pain at idle then trigger to alert

IdlePain[ ()
{
switch(random(1,4)) // chose between 4 animations
{
case 1
{
PlayAnimation(PAIN, true, "");
}
case 2
{
PlayAnimation(PAIN1, true, "");
}
case 3
{
PlayAnimation(PAIN2, true, "");
}
case 4
{
PlayAnimation(PAIN3, true, "");
}
}
SetEventState(ALERTTRIGGER, true); // set trigger to go to alert
Return();
} ]

// start shifting from idle to alert

IdleToAlert[ ()
{
FindTargetOrder(ALERTSIGHTDIST, "FoundTarget", DAMAGEATTRIBUTE); // increase viewing distance
AddPainOrder("AlertPain", PAINPERCENT); // show pain
AddTimerOrder(1, 10, "AlertToIdle"); // go to idle after 10 secs
SetEventState(ALERTTRIGGER, false); // turn off alert trigger
NewOrder("Alert");
} ]

// look around at alert looking for enemy

Alert[ ()
{
PlayAnimation(STAND, true, "");
if(random(1,10)>3) // turn around once in awhile
{
if(random(1,10)>5) // turn around to left
{
Rotate(TURNL, 102, 0, 90, 0, "");
Rotate(TURNL, 102, 0, 90, 0, "");
Rotate(TURNL, 102, 0, 90, 0, "");
Rotate(TURNL, 102, 0, 90, 0, "");
}
else // turn around to right
{
Rotate(TURNR, 108, 0, -90, 0, "");
Rotate(TURNR, 108, 0, -90, 0, "");
Rotate(TURNR, 108, 0, -90, 0, "");
Rotate(TURNR, 108, 0, -90, 0, "");
}
}
RestartOrder();
} ]

// show pain at alert

AlertPain[ ()
{
switch(random(1,4)) // play on of 4 animations
{
case 1
{
PlayAnimation(PAIN, true, "");
}
case 2
{
PlayAnimation(PAIN1, true, "");
}
case 3
{
PlayAnimation(PAIN2, true, "");
}
case 4
{
PlayAnimation(PAIN3, true, "");
}
}
Return();
} ]

// timed out at alert so go to idle

AlertToIdle[ ()
{
FindTargetOrder(SIGHTDIST, "FoundTarget", DAMAGEATTRIBUTE); // decrease viewing distance
AddPainOrder("IdlePain", 100); // show pain
AddTriggerOrder("IdleToAlert", ALERTTRIGGER, 0); // go to alert when triggered
NewOrder("Idle");
} ]

// found a target to attack

FoundTarget[ ()
{
DelTimerOrder(1); // get rid of alert timer
LowLevel(RUNFUNC); // attack functions are low level
} ]

// lost target while attacking so go back to idle again

LostTarget[ ()
{
FindTargetOrder(SIGHTDIST, "FoundTarget", DAMAGEATTRIBUTE); // seen a target to chase
AddPainOrder("IdlePain", 100); // show pain and trigger alert
AddTriggerOrder("IdleToAlert", ALERTTRIGGER, 0); // go to alert when triggered
NewOrder("Idle");
} ]

// killed target so back to idle

DeadTarget[ ()
{
FindTargetOrder(SIGHTDIST, "FoundTarget", DAMAGEATTRIBUTE); // seen a target to chase
AddPainOrder("IdlePain", 100); // show pain and trigger alert
AddTriggerOrder("IdleToAlert", ALERTTRIGGER, 0); // go to alert when triggered
NewOrder("Idle");
} ]

// you died

Death[ ()
{
DelTimerOrder(1); // remove alert timer
AddPainOrder("IdlePain", 0); // remove pain order
FindTargetOrder(0, "FoundTarget", DAMAGEATTRIBUTE); // remove target finding
DelTriggerOrder("IdleToAlert"); // remove alert trigger
SetNoCollision(); // remove bounding box so there are no collisions with corpse
switch(random(1,4)) // chose between 4 death animations
{
case 1
{
AnimateStop(DIE, DIEHOLD, "");
}
case 2
{
AnimateStop(DIE1, DIEHOLD, "");
}
case 3
{
AnimateStop(DIE2, DIEHOLD, "");
}
case 4
{
AnimateStop(DIE, DIEHOLD, "");
}
}
FadeOut(DIEFADE, 0); // fade out corpse
Remove(true); // remove actor
} ]

// Low level attack routines

// Start of run to attack

monster_run_start[ ()
{
Animate(RUN); // play run animation
self.ThinkTime = 0; // start thinking on next frame
self.think = "monster_run"; // go to run attack routine
self.ideal_yaw = enemy_yaw;
attack_state = AS_NONE; // not attacking yet
self.yaw_speed = YAWSPEED; // set rotation speed
melee_time = time;
back_up = false; // setup obsticle avoidance
} ]

// run to enemy to attack

monster_run[ ()
{
self.ThinkTime = 0.1; // think every 1/10 sec
if(self.health<=0)
{
HighLevel("Death"); // dead
return 0;
}
if((self.in_pain = true) and (random(1,100)<PAINPERCENT))
{
self.think = "monster_run_pain_start"; // in pain
return 0;
}
if(EnemyExist(DAMAGEATTRIBUTE) < 3)
{
HighLevel("LostTarget"); // enemy is gone or dead
return 0;
}
if(enemy_vis = false)
{
self.think = LOSTFUNC; // lost sight of enemy
lost_time = time + LOSTTIME;
return 0;
}
ai_run(random(RUNSPEED-2,RUNSPEED+2)); // run toward enemy

} ]

// start of pain while running

monster_run_pain_start[ ()
{
Animate(PAIN); // play pain animation
SetHoldAtEnd(true); // set to stop at animation end
self.ThinkTime = 0.1;
self.think = "monster_run_pain";
} ]

// wait for animation to stop

monster_run_pain[ ()
{
self.ThinkTime = 0.1;
if(self.animate_at_end = true) // wait for end of animation
{
self.think = "monster_run_start"; // start running again
SetHoldAtEnd(false); // remove animation stop
self.ThinkTime = 0;
}
} ]

// start of lost sight of enemy routine

monster_lost_target_start[ ()
{
Animate(RUN); // play run animation
self.ThinkTime = 0; // start thinking on next frame
self.think = "monster_lost_target";
} ]

// go to last known location of enemy

monster_lost_target[ ()
{
self.ThinkTime = 0.1;
if(lost_time<time)
{
HighLevel("LostTarget"); // timed out while looking
return 0;
}
if(self.health<=0)
{
HighLevel("Death"); // died
return 0;
}
if((self.in_pain = true) and (random(1,100)<PAINPERCENT))
{
self.think = "monster_lost_pain_start"; // in pain
return 0;
}
if(EnemyExist(DAMAGEATTRIBUTE) < 3)
{
HighLevel("LostTarget"); // enemy died or was removed
return 0;
}
if(enemy_vis = true)
{
self.think = "monster_run_start"; // seen again so run to attack
self.ThinkTime = 0;
return 0;
}
if(enemy_range>POINTRADIUS) // get close to last known location
{
walk_movetogoal(random(RUNSPEED-2,RUNSPEED+2)); // move to last knowm location
}
else
{
HighLevel("LostTarget"); // can't find at last known location
return 0;
}
} ]

// start of showing pain

monster_lost_pain_start[ ()
{
Animate(PAIN); // play pain animation
SetHoldAtEnd(true); // set to stop at end
self.ThinkTime = 0.1;
self.think = "monster_lost_pain";
} ]

// wait till animation is done

monster_lost_pain[ ()
{
self.ThinkTime = 0.1;
if(self.animate_at_end = true) // animation done
{
self.think = "monster_lost_target_start"; // go back to finding target
SetHoldAtEnd(false); // remove stop at end
self.ThinkTime = 0;
}
} ]

// start of melee attack

monster_melee_start[ ()
{
Animate(MELEEATTACK); // play melee attack animation
self.ThinkTime = 0;
self.think = "monster_melee";
} ]

// melee attack

monster_melee[ ()
{
self.ThinkTime = 0.1;
if(self.health<=0)
{
HighLevel("Death"); // you died
return 0;
}
if((self.in_pain = true) and (random(1,100)<PAINPERCENT))
{
self.think = "monster_melee_pain_start"; // in pain
return 0;
}
exist = EnemyExist(DAMAGEATTRIBUTE); // see if target is around
if(exist < 2)
{
HighLevel("LostTarget"); // enemy is dead and gone
return 0;
}
if(exist = 2)
{
HighLevel("DeadTarget"); // enemy is dead but body remains
return 0;
}
if(enemy_vis = false)
{
self.think = LOSTFUNC; // lost sight of enemy
lost_time = time + LOSTTIME;
return 0;
}
if(enemy_range>MELEERANGE)
{
self.think = RUNFUNC; // too far away so run toward
return 0;
}
ai_face(); // face enemy while attacking
if(time>melee_time) // if time then damage
{
damage = random(MINMELEEDAMAGE, MAXMELEEDAMAGE); // get damage amount
Damage(damage, DAMAGEATTRIBUTE); // damage target
melee_time = time + MELEEDELAY; // reset time until next damage
}
} ]

// start of showing pain

monster_melee_pain_start[ ()
{
Animate(PAIN); // play pain animation
SetHoldAtEnd(true); // set to stop at end
self.ThinkTime = 0.1;
self.think = "monster_melee_pain";
} ]

// wait until animation is done

monster_melee_pain[ ()
{
self.ThinkTime = 0.1;
if(self.animate_at_end = true) // animation is done
{
self.think = "monster_melee_start"; // go back to melee attack
SetHoldAtEnd(false);
self.ThinkTime = 0;
melee_time = time + MELEEDELAY; // reset attack deley
}
} ]




// basic AI routines

// run toward enemy and see if you are ready to attack

ai_run[ (dist)
{
if (attack_state = AS_MELEE) // do melee attack
{
ai_run_melee();
return 0;
}
if (CheckAnyAttack()) // check if you can start the actual attack
{
return 0;
}
walk_movetogoal(dist); // move toward the enemy
} ]

// melee attack setup

ai_run_melee[ ()
{
ai_face(); // turn to face target
if(FacingIdeal()) // got close enough
{
self.think = MELEEFUNC; // start melee attack
self.attack_state = AS_STRAIGHT;
}
} ]

// face enemy

ai_face[ ()
{
self.ideal_yaw = enemy_yaw;
ChangeYaw(); // rotate to face enemy
} ]

// use walkmove to navigate to enemy

walk_movetogoal[ (dist)
{
if(IsFalling = true)
{
return 0; // don't move while falling
}
if(back_up = false)
{
ai_face(); // turn to face enemy
if(FacingIdeal())
{
if(walkmove(self.current_yaw, dist) = true)
{
return 0; // can move in current direction
}
else // blocked
{
if(random(1,10)<3) // backup and move sideways sometimes
{
back_up = true;
back_time = time + 0.5;
back_flag = false;
return 0;
}
else
{
ForceUp(30); // jump up, forward and to side
ForceForward(30);
if(random(1,10)<6)
{
ForceRight(30);
}
else
{
ForceLeft(30);
}
}
}
}
}
else
{
if(back_flag = false) // go backward 1/2 sec
{
if(back_time > time)
{
walkmove((self.current_yaw-(180*0.0174532925199433)), dist);
return 0;
}
else
{
back_time = time + 0.5;
back_flag = true;
}
}
if(back_time > time) // go sideways 1/2 sec
{
walkmove((self.current_yaw-(90*0.0174532925199433)), dist);
return 0;
}
back_up = false;
}
} ]


// check if nearly facing enemy

FacingIdeal[ ()
{
selfangle = self.current_yaw/0.0174532925199433; // your direction in degrees
idealangle = self.ideal_yaw/0.0174532925199433; // his direction in degrees
delta = selfangle - idealangle; // difference in directions
if (delta > -20 and delta < 20) // within 20 degrees is close enough
{
return true;
}
return false;
} ]

// check if ready to do actual attacking

CheckAnyAttack[ ()
{
if(enemy_range<MELEERANGE) // inside melee range
{
attack_state = AS_MELEE; // do a melee attack
return true;
}
return false;
} ]

}

Re: Pawn Problem

Posted: Thu Apr 03, 2008 12:34 pm
by metal_head
Welcome to the forums!

Code: Select all

STAND [Idle] // idle animation
TURNL [TurnL] // turn left animation
TURNR [TurnR] // turn right animation

PAIN [Pain1] // pain animations
PAIN1 [Pain2]
PAIN2 [Pain3]
PAIN3 [Pain4]
PAINPERCENT [50] // percentage of time pain is shown

DIE [Die1] // dying animations
DIE1 [Die2]
DIE2 [Die3]
DIE3 [Die3]
DIEHOLD [15] // time corpse still appears
DIEFADE [10] // fadeout time of corpse

RUN [Run] // running animation
RUNSPEED [120] // average run speed

MELEEATTACK [Attack] // melee attacking animation
This is the list of the animations in the script.Open your actor with the Viewer.exe which you can find in your tools folder.You'll see the drop-down menu with the animations of the player.Just copy the name of the animation which you want to use from the viewer to the script.

Example:
My animation for running is named "Run_fast" ( but I don't know that yet)
I open the Viewer.exe and see what's the animation's name.
Than copy it to the script:

Code: Select all

RUN [Run_fast] // running animation
Save the script and try it!Now when he runs towards you,he should play the Run_fast animation.