Minor - Apparition du sprite du tir

Normalement, le spirte apparait bien lors de l'appui sur la touche espace
This commit is contained in:
NisemonoQ
2025-10-20 18:00:41 +02:00
parent 5624625eda
commit c7702b9f64
4 changed files with 16 additions and 18 deletions

View File

@@ -89,16 +89,17 @@ void AM4_PlayerPawn::Shoot(const FInputActionInstance& Inst)
{
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, TEXT("Using the Wand!"));
UWorld* const World = GetWorld();
if (World !=nullptr && Proj != nullptr)
if (!Proj && !World)
{
FVector TargetPosition = FVector3d(GetActorLocation().X, GetActorLocation().Y, GetActorLocation().Z);
FRotator SpawnRotation = UKismetMathLibrary::FindLookAtRotation(FVector3d(0), TargetPosition);
FVector TargetPosition = GetActorLocation();
FRotator SpawnRotation = GetActorRotation();
FActorSpawnParameters ActorSpawnParams;
ActorSpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButDontSpawnIfColliding;
ActorSpawnParams.Owner = this;
Projection = GetWorld()->SpawnActor<AM4_Projectile>(TargetPosition, SpawnRotation, ActorSpawnParams);
GetWorld()->SpawnActor<AM4_Projectile>(Proj, TargetPosition, SpawnRotation, ActorSpawnParams);
}
}

View File

@@ -8,14 +8,15 @@
// Sets default values
AM4_Projectile::AM4_Projectile()
{
MeshComp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MeshComp"));
MeshComp-> SetRelativeScale3D(FVector(1.f, .1f,.1f));
MeshComp->BodyInstance.SetCollisionProfileName(TEXT("Projectile"));
MeshComp->OnComponentHit.AddDynamic(this, &AM4_Projectile::OnHit);
ProjectileMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MeshComp"));
ProjectileMesh-> SetRelativeScale3D(FVector(1.f, .1f,.1f));
ProjectileMesh->BodyInstance.SetCollisionProfileName(TEXT("Projectile"));
ProjectileMesh->OnComponentHit.AddDynamic(this, &AM4_Projectile::OnHit);
ProjectileMesh->SetupAttachment(RootComponent);
ProjectileMesh->SetMobility(EComponentMobility::Movable);
ProjectileMesh->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
MeshComp->SetupAttachment(RootComponent);
MeshComp->SetMobility(EComponentMobility::Movable);
MeshComp->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
}
void AM4_Projectile::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector Impulse, const FHitResult& Hit)

View File

@@ -34,12 +34,8 @@ protected:
UInputAction* ShootAction;
UPROPERTY(VisibleAnywhere)
AM4_Projectile* Proj;
UPROPERTY(VisibleAnywhere)
TObjectPtr<AM4_Projectile> Projection;
TSubclassOf<AM4_Projectile> Proj;
//bool HasShot = false;
float MoveSpeed = 500.f;
FVector2D MeshScale = FVector2D(0.6f, 0.5f);
FVector2D LastMoveValue = FVector2D::ZeroVector;

View File

@@ -28,7 +28,7 @@ public:
// Despawn after 5 seconds by default
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Projectile | Lifespan")
float ProjectileLifespan = 5.0f;
float ProjectileLifespan = 3.0f;
// The amount of force this projectile imparts on objects it collides with
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Projectile | Physics")