Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void AROMCharacter::OnFire()
- {
- // try and fire a projectile
- if (ProjectileClass != NULL)
- {
- // Get the camera transform
- FVector CameraLoc;
- FRotator CameraRot;
- GetActorEyesViewPoint(CameraLoc, CameraRot);
- // MuzzleOffset is in camera space, so transform it to world space before offsetting from the camera to find the final muzzle position
- FVector const MuzzleLocation = CameraLoc + FTransform(CameraRot).TransformVector(MuzzleOffset);
- FRotator MuzzleRotation = CameraRot;
- MuzzleRotation.Pitch += 10.0f; // skew the aim upwards a bit
- UWorld* const World = GetWorld();
- if (World)
- {
- FActorSpawnParameters SpawnParams;
- SpawnParams.Owner = this;
- SpawnParams.Instigator = Instigator;
- // spawn the projectile at the muzzle
- AROMProjectile* const Projectile = World->SpawnActor<AROMProjectile>(ProjectileClass, MuzzleLocation, MuzzleRotation, SpawnParams);
- if (Projectile)
- {
- // find launch direction
- FVector const LaunchDir = MuzzleRotation.Vector();
- Projectile->InitVelocity(LaunchDir);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement