pawn attack

Topics regarding Scripting with Reality Factory
User avatar
creekmonkey
Posts: 116
Joined: Tue Oct 23, 2007 2:55 pm

pawn attack

Post 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.
User avatar
darksmaster923
Posts: 1857
Joined: Wed Jan 03, 2007 10:32 pm
Location: Huntington Beach, California, USA

Post 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
Herp derp.
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Post 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();
Pain is only psychological.
User avatar
creekmonkey
Posts: 116
Joined: Tue Oct 23, 2007 2:55 pm

Post 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
} ]
User avatar
creekmonkey
Posts: 116
Joined: Tue Oct 23, 2007 2:55 pm

Post 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.
User avatar
bernie
RF Moderator
Posts: 1249
Joined: Tue Nov 15, 2005 10:07 am
Location: Ireland

Post 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.
User avatar
bernie
RF Moderator
Posts: 1249
Joined: Tue Nov 15, 2005 10:07 am
Location: Ireland

Post by bernie »

And of course set gravity(false) in the setup or spawn routine.
User avatar
creekmonkey
Posts: 116
Joined: Tue Oct 23, 2007 2:55 pm

Post by creekmonkey »

Thanks Bernie
That did the trick!
User avatar
creekmonkey
Posts: 116
Joined: Tue Oct 23, 2007 2:55 pm

Post 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?
User avatar
bernie
RF Moderator
Posts: 1249
Joined: Tue Nov 15, 2005 10:07 am
Location: Ireland

Post 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.
User avatar
creekmonkey
Posts: 116
Joined: Tue Oct 23, 2007 2:55 pm

Post 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
User avatar
bernie
RF Moderator
Posts: 1249
Joined: Tue Nov 15, 2005 10:07 am
Location: Ireland

Post 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.
User avatar
creekmonkey
Posts: 116
Joined: Tue Oct 23, 2007 2:55 pm

Post 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?
User avatar
bernie
RF Moderator
Posts: 1249
Joined: Tue Nov 15, 2005 10:07 am
Location: Ireland

Post 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.
User avatar
creekmonkey
Posts: 116
Joined: Tue Oct 23, 2007 2:55 pm

Post by creekmonkey »

Thanks again bernie, guys like you make it possible for guys like me to learn RF.
Post Reply