Beispiel #1
0
void ALauncherWeapon::Fire()
{

	Super::Fire();
	// try and fire a projectile
	if (GrenadeArchetype != NULL)
	{

		UWorld* const World = GetWorld();
		if (World && Mesh1P)
		{

			FActorSpawnParameters SpawnParams;
			SpawnParams.Owner = this;
			SpawnParams.Instigator = Instigator;
			// spawn the projectile at the muzzle
			//FVector loc = Mesh1P->GetSocketLocation(TEXT("MuzzleFlashSocket"));
			//FRotator rot = Mesh1P->GetSocketRotation(TEXT("MuzzleFlashSocket"));
		
		//	DrawDebugLine(GetWorld(),loc,loc+rot.Vector()*400,FColor::Red);

			AProjectile* theProjectile = World->SpawnActor<AProjectile>(GrenadeArchetype, Mesh1P->GetSocketLocation(TEXT("MuzzleFlashSocket")), Mesh1P->GetSocketRotation(TEXT("MuzzleFlashSocket")));
			//AProjectile* theProjectile = World->SpawnActor<AProjectile>(GrenadeArchetype,loc,rot );

			if (theProjectile)
			{
				// find launch direction
				theProjectile->InitVelocity(Mesh1P->GetSocketRotation(TEXT("MuzzleFlashSocket")).Vector());

			}
		}
	}
}
Beispiel #2
0
void ALauncherWeapon::Fire()
{
	Super::Fire();

	if (GrenadeArchetype)
	{
		UWorld* const World = GetWorld();
		if (World && Mesh1P && ThePlayer && ThePlayer->Controller)
		{
			// Get Camera Rotation
			FVector CamLoc;
			FRotator CamRot;
			ThePlayer->Controller->GetPlayerViewPoint(CamLoc, CamRot);

			// Calculate Origin and Direction of Fire
			const FVector StartTrace = GetFireSocketTransform().GetLocation();
			const FVector Direction = CamRot.Vector();

			// Set Spawn Paramets
			FActorSpawnParameters SpawnParams;
			SpawnParams.Owner = this;
			SpawnParams.Instigator = Instigator;


			// Spawn at Fire socket location
			AProjectile* TheProjectile = World->SpawnActor<AProjectile>(GrenadeArchetype, StartTrace, CamRot);

			// Set Projectile Velocity
			if (TheProjectile) 
			{
				
				TheProjectile->InitVelocity(Direction*ProjectileVelocity);
			}
				
		}
	}
}