Tower not allowing spawn

so the tank worked perfectly fine, but the tower does not allow me to use the projectile class, and then the tank decides not to either as seen in these screenshots:



here is the code for them:
BasePawn.h
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include “CoreMinimal.h”

#include “GameFramework/Pawn.h”

#include “BasePawn.generated.h”

UCLASS()

class TOONTANKS_API ABasePawn : public APawn

{

GENERATED_BODY()

public:

// Sets default values for this pawn's properties

ABasePawn();

protected:

void RotateTurret(FVector LookAtTarget);

void Fire();

private:

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))

class UCapsuleComponent* CapsuleComp;

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))

UStaticMeshComponent* BaseMesh;

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))

UStaticMeshComponent* TurretMesh;

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))

USceneComponent* ProjectileSpawnPoint;

UPROPERTY(EditDefaultsOnly, Category = "Combat")

TSubclassOf<class AProjectile> ProjectileClass;

};

BasePawn.cpp

// Fill out your copyright notice in the Description page of Project Settings.

#include “BasePawn.h”

#include “Components/CapsuleComponent.h”

#include “Kismet/GameplayStatics.h”

#include “Projectile.h”

// Sets default values

ABasePawn::ABasePawn()

{

// Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.

PrimaryActorTick.bCanEverTick = true;



CapsuleComp = CreateDefaultSubobject<UCapsuleComponent>(TEXT("Capsule Collider"));

RootComponent = CapsuleComp;

BaseMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Base Mesh"));

BaseMesh->SetupAttachment(CapsuleComp);

TurretMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Turret Mesh"));

TurretMesh->SetupAttachment(BaseMesh);

ProjectileSpawnPoint = CreateDefaultSubobject<USceneComponent>(TEXT("Spawn Point"));

ProjectileSpawnPoint->SetupAttachment(TurretMesh);

}

// Called when the game starts or when spawned

void ABasePawn::RotateTurret(FVector LookAtTarget)

{

FVector ToTarget = LookAtTarget - TurretMesh->GetComponentLocation();

FRotator LookAtRotation = FRotator(0.f, ToTarget.Rotation().Yaw, 0.f);

TurretMesh->SetWorldRotation(FMath::RInterpTo(TurretMesh->GetComponentRotation(),

LookAtRotation, UGameplayStatics::GetWorldDeltaSeconds(this), 2.f));

}

void ABasePawn::Fire()

{

FVector Location = ProjectileSpawnPoint->GetComponentLocation();

FRotator Rotation = ProjectileSpawnPoint->GetComponentRotation();

GetWorld()->SpawnActor<AProjectile>(ProjectileClass, Location, Rotation);

}

Could you show your projectile blueprint?

for some reason it does it now, maybe it is because I restarted it

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms