Page 1 of 2

pawn attack

Posted: Tue Dec 18, 2007 9:53 pm
by creekmonkey
Is there a way of getting a pawn to attack actor correctly if actor is higher or lower than pawn?

I have a pawn which is a shark. It swims ok and its depth can vary when following script points. But I need the shark to change its pitch and attack in that direction if the actor's y position is higher or lower than the pawn. I have serched the forum for quite a long time and cant seem to find any reference to this. Is it even posible?

Thanks in advance for any help.

Posted: Wed Dec 19, 2007 5:51 am
by darksmaster923
certainly
there are many ways to do this though
you can make it align its pitch to the enemies, but to really do this depends on ur kknowledge

Posted: Wed Dec 19, 2007 11:08 am
by Juutis
The manual:
self.enemy_pitch

A read-only variable that contains the pitch angle, in radians, the Pawn must face to be pointing at the target.
self.ideal_pitch

A variable that must contain the pitch angle, in radians, that you wish to have the Pawn rotate to. Used by the rotation functions when rotating the Pawn.
ChangePitch();

Rotate the Pawn's actor from its current pitch angle towards the pitch angle specified by self.ideal_pitch at a speed of self.pitch_speed degrees per second. When the Pawn's pitch angle reaches the desired angle, rotation will cease.

... so basically it is very easy to make the a pawn change its pitch:

Code: Select all

self.ideal_pitch = self.enemy_pitch;
ChangePitch();

Posted: Thu Dec 20, 2007 2:59 pm
by creekmonkey
I am not able to get the shark pawn to change pitch, I have placed the code in the lowlevel attack routine
"monster_run_start" but that doesnt work. Is this the correct routine to place the code in?

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

Posted: Thu Dec 20, 2007 6:38 pm
by creekmonkey
I was able to get the pawn to change pitch by placing
self.ideal_pitch in the monster_run_start routine

and placing in the ai_face routine


self.ideal_yaw = enemy_yaw;
ChangeYaw(); // rotate to face enemy
self.ideal_pitch = enemy_pitch;
ChangePitch();

The Pawn does change pitch now and attacks, but will not attack in the direction of the pitch.
What am I doing wrong here?

By the way I am using a modifed genericmelee script.
I tried using the flock.s script but when the pawn gets close during attack he turns away and goes back to script points.

Posted: Thu Dec 20, 2007 6:57 pm
by bernie
In the "walk_movetogoal" routine you need to change "if(walkmove(self.current_yaw, dist) = true)" to
"if(flymove(self.current_pitch, self.current_yaw, dist) = true)"
and change
"walkmove((self.current_yaw-(180*0.0174532925199433)), dist);"
to "flymove((self.current_pitch-(180*0.0174532925199433)),(self.current_yaw-(180*0.0174532925199433)), dist);"

That should make it work.

Posted: Thu Dec 20, 2007 7:11 pm
by bernie
And of course set gravity(false) in the setup or spawn routine.

Posted: Thu Dec 20, 2007 7:13 pm
by creekmonkey
Thanks Bernie
That did the trick!

Posted: Thu Dec 20, 2007 7:23 pm
by creekmonkey
One other question
Is there a way to limit how high on the y axis the pawn can go?
So it doesnt come out of water?

Posted: Thu Dec 20, 2007 8:07 pm
by bernie
Yes, you can check the self.current_Y variable to find where the pawn is on the y axis and not allow movement above that point. It would proabably get complicated but I am sure it can be done.

Posted: Thu Dec 20, 2007 8:19 pm
by creekmonkey
I have tried that Bernie
Currently I have an if statement in the walkmove routine
if(self.current_Y >-144)
{
return 0;
}

If I put anything there
return 0;
return ;
exct

the shark stops, but I can not get it to leave the attack routine.
I tried puting NewOrder("LostTarget") Idle, or patrol but still nothing happens till the player moves out of sight distance

Posted: Thu Dec 20, 2007 8:38 pm
by bernie
LostTarget is a High Level order. Use the order HighLevel("LostTarget"); as the order. You can't use the NewOrder command (which is a High Level command) in a Low level routine. I know it's complicated but you can't mix high level and low level commands in the same routine.

Posted: Thu Dec 20, 2007 11:09 pm
by creekmonkey
That works bernie

Am able to send the pawn back to patroling when it reaches a certain point on the y axis, but now the pitch wont return to its original state.

Also is there a way to get the pitch for a scriptpoint like you can with enemy.ideal_pitch?

Posted: Fri Dec 21, 2007 12:31 pm
by bernie
In the Patrol routine change
RotateMoveToPoint(WALK, YAWSPEED, WALKSPEED*SCALE, false, WALKSOUND);
to
RotateMoveToPoint(WALK, YAWSPEED, WALKSPEED*SCALE, true, WALKSOUND);
That should sort it.

Posted: Sat Dec 22, 2007 3:30 am
by creekmonkey
Thanks again bernie, guys like you make it possible for guys like me to learn RF.