I’m trying to create a simple projectile for my side scrolling shooter.
I’ve taken a look at how it’s done with the First Person C++ template, and it seems simple enough:
Add the projectile.cpp and .h classes, then create a projectile
I have my firing input set to left-mouse button, and I can see it being called when I set a breakpoint. However, projectile always returns null, so it skips over the function.
void AFlyingPawn::OnFire()
{
// try and fire a pr
ojectile
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
AFirstpersonProjectile* const Projectile = World->SpawnActor(ProjectileClass, MuzzleLocation, MuzzleRotation, SpawnParams);
if (Projectile)
{
// find launch direction
FVector const LaunchDir = MuzzleRotation.Vector();
Projectile->InitVelocity(LaunchDir);
}
}
}
}
I also have the projectile class referenced in my FlyingPawn.h
/** Projectile class to spawn */
UPROPERTY(EditDefaultsOnly, Category=Projectile)
TSubclassOf ProjectileClass;
I’ve created a projectile blueprint which is identical to the one seen in the First Person template, but they is one thing I can’t seem to find: Collision Preset: Projectile
In the First Person Template, the blueprint has the option to set the collision as Projectile. (this is found just beneath Vehicle).
In my game, I don’t see an option for projectile, which leads me to believe that I am doing something wrong.
1) Why is my projectile always returning null
2) Where do I find this collision preset for projectile?