Created
December 7, 2010 02:29
-
-
Save tjpeden/731368 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@name Automated Turret | |
@outputs Fire | |
@persist Self:entity Turret:entity Target:entity Angle:angle | |
@persist Threshold | |
if( first() ) { | |
runOnTick(1) | |
Self = entity() | |
Self:isWeldedTo():setMaterial( "Models/XQM/LightLinesRed" ) | |
Threshold = 1000 | |
findExcludeEntity( owner() ) | |
} | |
if( !Turret ) { | |
if( ->Fire ) { | |
Es = ioOutputEntities("Fire") | |
Turret = Es[1, entity] | |
} | |
} | |
if( Turret & tickClk() ) { | |
P = Self:pos() + vec( 0, 0, 10 ) | |
if( !Target & findCanQuery() ) { | |
findByClass( "player" ) | |
N = findClipToSphere( Turret:pos(), Threshold ) | |
Fire = !!N | |
if( N > 0 ) { | |
Target = findClosest( Self:pos() ) | |
} | |
} | |
if( Target ) { | |
if( Turret:pos():distance( Target:pos() ) > Threshold ){ | |
Target = noentity() | |
exit() | |
} | |
Pos = Target:pos() + vec( random(-5, 5), random(-5, 5), Target:height() / 2 ) | |
Angle = ( Pos - Turret:pos() ):toAngle() | |
rangerFilter( Turret ) | |
RD = rangerOffset( Turret:pos(), Pos ) | |
Fire = RD:entity() == Target | |
} else { Angle = Self:angles() } | |
TarQ = quat( Angle ) | |
CurQ = quat( Turret ) | |
Q = TarQ/CurQ | |
V = Turret:toLocal( rotationVector( Q ) + P ) | |
Turret:applyTorque( ( 150 * V - 12 * Turret:angVelVector() ) * Turret:inertia() ) | |
Turret:applyForce( ( ( P - Turret:massCenter() ) * 10 - Turret:vel() ) * Turret:mass() ) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment