Page 1 of 1

Scripted Player Pawn Aiming help needed

Posted: Mon Jun 04, 2007 4:32 pm
by Masta_J
Sup guys, I have two questions:

1) How do I enable my player pawn to fire projectiles in the direction of the mouse crosshair? I've tried the LowLevel, "MouseControlledPlayer(true);", command in my pawn's setup, but it does nothing (I assume this command refers to the built in player).

2) How do I get my player pawn to auto target the nearest enemy pawn? I would like to add this my attack commands, namely:

Code: Select all

Punch[() 
{ 
    if(ATTACKDELAY < self.time)  // see if enough time has passed since the animation started 
    { 
   FireProjectileBlind(FIREAMMO1,WEAPONHAND2,0,0,0,DAMAGEATTRIB);  // shoot the projectile (= do the damage) 
   attackdelay = self.time + 10000;   // make sure the damage is done only once 
    } 

    if(self.animate_at_end)  // check if the animation has finished 
    { 
        self.think="Test";  // go back to the basic routines 
        return 0; 
    } 

}]

AND

Blast[()
{
if(self.animate_at_end)
{
FireProjectileBlind(FIREAMMO4,WEAPONHAND,0,-8,10,DAMAGEATTRIB); // shoot the projectile (= do the damage)
FireProjectileBlind(FIREAMMO4,WEAPONHAND,0,-8,10,DAMAGEATTRIB);
if(self.animate_at_end)
{
self.think="GalickGunFire2"; // go back to the basic routines
return 0;
}
}]

Much appreciated

Posted: Mon Jun 04, 2007 8:45 pm
by zany_001
well i thought there was a tute,right here,stickied,for autoaim,but it seems to be gone,ill see if i can find it.

Posted: Mon Jun 04, 2007 10:42 pm
by Jay
1) what camera are you using? third person? first person? would be good to know, because it CAN be done but it is important to know which camera you are using...

Posted: Tue Jun 05, 2007 4:04 pm
by Masta_J
I'm using a third person camera view.

Posted: Tue Jun 05, 2007 9:03 pm
by Jay
you 'just' have to compute a 'target point' relative to the pawn. This is the direction the pawn will shoot at. (this only works if the camera is directly behind the pawn). And then you have to fire the projectile in the direction specified.

FIREOFFSETX, -Y and -Z specify the source point in relation to the shoot bone.

Code: Select all

FIREOFFSETX   [0]
FIREOFFSETY   [0]
FIREOFFSETZ   [0]

Shoot[ ()
{
   SetTargetPoint(FIREOFFSETX,sin(self.camera_pitch)+FIREOFFSETY,1+FIREOFFSETZ);
   FireProjectile(FIREAMMO1,WEAPONHAND2,FIREOFFSETX,FIREOFFSETY,FIREOFFSETZ,DAMAGEATTRIB);
} ]
i am not 100% sure if this works though. You may have to replace

Code: Select all

   SetTargetPoint(FIREOFFSETX,sin(self.camera_pitch)+FIREOFFSETY,1+FIREOFFSETZ);
with

Code: Select all

   SetTargetPoint(FIREOFFSETX,sin(self.camera_pitch)*(-1)+FIREOFFSETY,1+FIREOFFSETZ);
Please tell me if this works, because i am just guessing here.