Make actor aim vertical: Difference between revisions

From EDukeWiki
Jump to navigation Jump to search
edited for grammar (mb)
Sangman (talk | contribs)
New way to do this based on Hendricks' suggestion
Line 6: Line 6:
{
{
         ldist TEMP THISACTOR ACTOR2
         ldist TEMP THISACTOR ACTOR2
        getprojectile[SHOTSPARK1].vel PROJECTILE_VEL
        ifn PROJECTILE_VEL 0
            div TEMP PROJECTILE_VEL // distance / projectile velocity = the amount of tics it would take for the projectile to reach the player's position (regardless of Z coordinate)
         getactor[THISACTOR].z TEMP2
         getactor[THISACTOR].z TEMP2
        subvar TEMP2 8192 // Offset the Z. Assumes the center of the actor is the same as the player
         getactor[ACTOR2].z TEMP3
         getactor[ACTOR2].z TEMP3
         subvar TEMP3 8192 // Offset the Z. assumes the center of the actor is the same as the player
         sub TEMP3 TEMP2
        subvarvar TEMP3 TEMP2
 
         shiftvarl TEMP3 8
         ifn TEMP 0
        divvarvar TEMP3 TEMP
            div TEMP3 TEMP
 
         zshoot TEMP3 SHOTSPARK1  
         zshoot TEMP3 SHOTSPARK1  
}
}

Revision as of 12:51, 6 September 2019

In this example, the actor will find the closest LIZTROOP actor within 2048 units and calculate the vertical angle it needs to aim at. This code is an example of how to use the zshoot command to create friendly bots and other similar effects. The following does not contain the gamevar definitions, which must be placed outside of the actor code.

findnearactor LIZTROOP 2048 ACTOR2
ifvarn ACTOR2 -1
{
        ldist TEMP THISACTOR ACTOR2
        getprojectile[SHOTSPARK1].vel PROJECTILE_VEL

        ifn PROJECTILE_VEL 0
            div TEMP PROJECTILE_VEL // distance / projectile velocity = the amount of tics it would take for the projectile to reach the player's position (regardless of Z coordinate)

        getactor[THISACTOR].z TEMP2
        getactor[ACTOR2].z TEMP3
        sub TEMP3 TEMP2 

        ifn TEMP 0
            div TEMP3 TEMP

        zshoot TEMP3 SHOTSPARK1 
}