For some reason the movement speed of the projectile is (but also isn’t) changing. I’ll explain. Basically I initially noticed that whatever I changed Movement Speed to in the BP changed nothing, it kept firing out in front of me. I then went to the projectile movement component and saw that both the Initial and Max speed were both set to 0, which I thought was strange as I had used the pointers from the lecture. So I manually changed them to 1300 and the projectile started launching as expected. And I thought well I want to change both by changing the movement speed, that was the point of the pointers (no pun intended) so I’ll try changing movement speed and see what happens. I changed it to less than 1300, works as intended. Okay, great. Try changing it to above 1300 (say 2500). Still launches as if it was set at 1300. Aha, so movement speed doesn’t alter anything unless it MovementSpeed <= Initial/Max Speed, which I don’t believe was the intention here? I don’t think I’m missing anything. But here’s my code.
ProjectileBase.h:
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "ProjectileBase.generated.h"
class UProjectileMovementComponent;
UCLASS()
class TOONTANKS_API AProjectileBase : public AActor
{
GENERATED_BODY()
private:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
UProjectileMovementComponent* ProjectileMovement;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
UStaticMeshComponent* ProjectileMesh;
UPROPERTY(EditDefaultsOnly, Category = "Damage")
TSubclassOf<UDamageType> DamageType;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Move", meta = (AllowPrivateAccess = "true"))
float MovementSpeed = 1300.f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Damage", meta = (AllowPrivateAccess = "true"))
float Damage = 50.f;
public:
// Sets default values for this actor's properties
AProjectileBase();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
};
ProjectileBase.cpp:
#include "ProjectileBase.h"
#include "Components/StaticMeshComponent.h"
#include "GameFramework/ProjectileMovementComponent.h"
// Sets default values
AProjectileBase::AProjectileBase()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = false;
ProjectileMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Projectile Mesh"));
RootComponent = ProjectileMesh;
ProjectileMovement = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("Projectile Movement"));
}
// Called when the game starts or when spawned
void AProjectileBase::BeginPlay()
{
Super::BeginPlay();
ProjectileMovement->InitialSpeed = MovementSpeed;
ProjectileMovement->MaxSpeed = MovementSpeed;
InitialLifeSpan = 3.f;
}
My spawn points are 100 units out from the turret, and I’ve tried moving the code under BeginPlay back to the contructor and that didn’t change anything either.