Advertisement
inkoalawetrust

Broken aim prediction code.

Oct 26th, 2022 (edited)
709
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.56 KB | Source Code | 0 0
  1. //The function
  2.     Void HandleTargetPrediction (Actor Projectile, Vector2 SpreadHorz, Vector2 SpreadVert)
  3.     {
  4.         Vector3 OldVel;
  5.         If (!Projectile || !Target) Return;
  6.        
  7.         //Target has no velocity for VelIntercept to work with. This is almost always the case for normal NPCs, which move using small teleport steps, instead of actual movement.
  8.         If ((Target.Vel.X == 0 && Target.Vel.Y == 0 && Target.Vel.Z == 0))
  9.         {
  10.             OldVel = Target.Vel;
  11.             //Temporarily change the zero velocity actors' vel to the difference between their current and last ticks' position.
  12.             //If (TicsSinceLastMove)
  13.             //{ Target.Vel = Level.Vec3Diff (Target.Pos,LastEnemyPosition) / TicsSinceLastMove;a_log ("divided");}
  14.             //Else
  15.                 Target.Vel = Level.Vec3Diff (Target.Pos,LastEnemyPosition);
  16.             If ((Target.Vel.X == 0 && Target.Vel.Y == 0 && Target.Vel.Z == 0)) //Still no velocity
  17.             {a_log ("no velocity still, falling back to normal aiming");
  18.                 Projectile.Angle += FRandom (SpreadHorz.X,SpreadHorz.Y);
  19.                 Projectile.Pitch += FRandom (SpreadVert.X,SpreadVert.Y);
  20.                 //Projectile.Vel3DFromAngle (Projectile.Speed,Projectile.Angle,Projectile.Pitch);
  21.                 Target.Vel = OldVel;
  22.                 Return; //Just add in the projectile spread and finish.
  23.             }
  24.             Console.Printf ("The targets' current pos is: %f, %f, %f",Target.Pos.X,Target.Pos.Y,Target.Pos.Z);
  25.             Console.Printf ("The targets' last pos was: %f, %f, %f",LastEnemyPosition.X,LastEnemyPosition.Y,LastEnemyPosition.Z);
  26.             Console.Printf ("The targets' velocity is now: %f, %f, %f",Target.Vel.X,Target.Vel.Y,Target.Vel.Z);
  27.             Console.Printf ("TicsSinceLastMove is: %d",TicsSinceLastMove);
  28.             Console.Printf ("==============================================");
  29.             Projectile.VelIntercept (Target);
  30.             //Projectile.Angle += FRandom (SpreadHorz.X,SpreadHorz.Y);
  31.             //Projectile.Pitch += FRandom (SpreadVert.X,SpreadVert.Y);
  32.             Projectile.Vel3DFromAngle (Projectile.Speed,Projectile.Angle,Projectile.Pitch);
  33.             Target.Vel = OldVel;
  34.         }
  35.         //Target has velocity, like if it's a player or a custom actor with velocity-based movement.
  36.         Else
  37.             Projectile.VelIntercept (Target);
  38.     }
  39.  
  40. //The Tick() override on the shooter.
  41.  
  42.     Override Void Tick()
  43.     {
  44.         Actor.Tick();
  45.        
  46.         /*If (Target && Target.Pos == LastEnemyPosition)
  47.             TicsSinceLastMove++;
  48.         Else
  49.             TicsSinceLastMove = 0;
  50.         */
  51.         If (Target && Target.Pos != LastEnemyPosition) LastEnemyPosition = Target.Pos;
  52.        
  53.         //Unrelated stuff.
  54.         If (!Master || IsFrozen() || IsDead(Self) && bFallOnDeath) Return;
  55.        
  56.         SetOrigin (Master.Vec3Offset(TurretOffsets.X,TurretOffsets.Y,Master.Height+TurretOffsets.Z),True);
  57.     }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement