Advertisement
Guest User

Character.cpp

a guest
Oct 11th, 2014
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1.     void AROMCharacter::OnFire()
  2.     {
  3.         // try and fire a projectile
  4.         if (ProjectileClass != NULL)
  5.         {
  6.             // Get the camera transform
  7.             FVector CameraLoc;
  8.             FRotator CameraRot;
  9.             GetActorEyesViewPoint(CameraLoc, CameraRot);
  10.             // MuzzleOffset is in camera space, so transform it to world space before offsetting from the camera to find the final muzzle position
  11.             FVector const MuzzleLocation = CameraLoc + FTransform(CameraRot).TransformVector(MuzzleOffset);
  12.             FRotator MuzzleRotation = CameraRot;
  13.             MuzzleRotation.Pitch += 10.0f;          // skew the aim upwards a bit
  14.             UWorld* const World = GetWorld();
  15.             if (World)
  16.             {
  17.                 FActorSpawnParameters SpawnParams;
  18.                 SpawnParams.Owner = this;
  19.                 SpawnParams.Instigator = Instigator;
  20.                 // spawn the projectile at the muzzle
  21.                 AROMProjectile* const Projectile = World->SpawnActor<AROMProjectile>(ProjectileClass, MuzzleLocation, MuzzleRotation, SpawnParams);
  22.                 if (Projectile)
  23.                 {
  24.                     // find launch direction
  25.                     FVector const LaunchDir = MuzzleRotation.Vector();
  26.                     Projectile->InitVelocity(LaunchDir);
  27.                 }
  28.             }
  29.         }
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement