Creating the projectile
Now we have a player character and we have a cross hair, all we need now is something to shoot! We need to create an object that can be fired forward and act the same way a weighted projectile would under the effects of gravity, similar to a grenade or small cannon ball. We can do this by utilizing another movement-based component. This one is called a ProjectileMovementComponent
and can be used alongside the physics engine to dictate how a projectile will move through space. Using the C++ class wizard create a class that inherits from Actor called BMProjectile
.
Defining the Projectile
Let's start by defining the ABMProjectile
class. We can begin with the private members of the class, navigate to BMProjectile.h
and add the following code to the class definition under GENERATED_BODY()
:
/** Sphere collision component */ UPROPERTY(VisibleDefaultsOnly, Category = Projectile) class USphereComponent* ProjCollision; UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Projectile...