I’ve been following the UE4 First Person C++ Tutorial, and so far, I have been able to figure out the things that the tutorial left out (since it was made in 4.15). But I have been trying this one for awhile, and I cant seem to figure out the problem. I know that it has to do with the setup of my projectile’s movement parameters, but nothing I seem to do works. The project name is LearningCurve. Is there something that I’m missing?
LearningCurveProjectile.cpp
#include "LearningCurveProjectile.h"
#include "Components/SphereComponent.h"
#include "GameFramework/ProjectileMovementComponent.h"
// Sets default values
ALearningCurveProjectile::ALearningCurveProjectile()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
// Use a sphere as simple collision representation
CollisionComponent = CreateDefaultSubobject<USphereComponent>(TEXT("SphereComponent"));
// Set the collision radius
CollisionComponent->InitSphereRadius(15.0f);
// Set root component to collision component
RootComponent = CollisionComponent;
// Use this component to drive this projectile's movement.
ProjectileMovementComponent = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("ProjectileMovementComponent"));
ProjectileMovementComponent->SetUpdatedComponent(CollisionComponent);
ProjectileMovementComponent->InitialSpeed = 3000.0f;
ProjectileMovementComponent->MaxSpeed = 3000.0f;
ProjectileMovementComponent->bRotationFollowsVelocity = true;
ProjectileMovementComponent->bShouldBounce = true;
ProjectileMovementComponent->Bounciness = 0.3f;
}
// Called when the game starts or when spawned
void ALearningCurveProjectile::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void ALearningCurveProjectile::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Function that initializes the projectile's velocity in the shoot direction.
void ALearningCurveProjectile::FireInDirection(const FVector& ShootDirection)
{
ProjectileMovementComponent->Velocity = ShootDirection * ProjectileMovementComponent->InitialSpeed;
}
LearningCurveProjectile.h
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "LearningCurveProjectile.generated.h"
UCLASS()
class LERANINGCURVE_API ALearningCurveProjectile : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
ALearningCurveProjectile();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Sphere collision component.
UPROPERTY(VisibleDefaultsOnly, Category = Projectile)
USphereComponent* CollisionComponent;
// Projectile movement component.
UPROPERTY(VisibleAnywhere, Category = Movement)
UProjectileMovementComponent* ProjectileMovementComponent;
// Function that initializes the projectile's velocity in the shoot direction.
void FireInDirection(const FVector& ShootDirection);
};