From c7702b9f646f88b776515a8d9ac96c0c16953227 Mon Sep 17 00:00:00 2001 From: NisemonoQ Date: Mon, 20 Oct 2025 18:00:41 +0200 Subject: [PATCH] Minor - Apparition du sprite du tir Normalement, le spirte apparait bien lors de l'appui sur la touche espace --- Source/M4_CPP/private/M4_PlayerPawn.cpp | 11 ++++++----- Source/M4_CPP/private/M4_Projectile.cpp | 15 ++++++++------- Source/M4_CPP/public/M4_PlayerPawn.h | 6 +----- Source/M4_CPP/public/M4_Projectile.h | 2 +- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/Source/M4_CPP/private/M4_PlayerPawn.cpp b/Source/M4_CPP/private/M4_PlayerPawn.cpp index 1804e9a..664ea3e 100644 --- a/Source/M4_CPP/private/M4_PlayerPawn.cpp +++ b/Source/M4_CPP/private/M4_PlayerPawn.cpp @@ -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(TargetPosition, SpawnRotation, ActorSpawnParams); + GetWorld()->SpawnActor(Proj, TargetPosition, SpawnRotation, ActorSpawnParams); + } } diff --git a/Source/M4_CPP/private/M4_Projectile.cpp b/Source/M4_CPP/private/M4_Projectile.cpp index 8f8efb4..1bdc24e 100644 --- a/Source/M4_CPP/private/M4_Projectile.cpp +++ b/Source/M4_CPP/private/M4_Projectile.cpp @@ -8,14 +8,15 @@ // Sets default values AM4_Projectile::AM4_Projectile() { - MeshComp = CreateDefaultSubobject(TEXT("MeshComp")); - MeshComp-> SetRelativeScale3D(FVector(1.f, .1f,.1f)); - MeshComp->BodyInstance.SetCollisionProfileName(TEXT("Projectile")); - MeshComp->OnComponentHit.AddDynamic(this, &AM4_Projectile::OnHit); + ProjectileMesh = CreateDefaultSubobject(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) diff --git a/Source/M4_CPP/public/M4_PlayerPawn.h b/Source/M4_CPP/public/M4_PlayerPawn.h index 9cc6ca1..a9f9be6 100644 --- a/Source/M4_CPP/public/M4_PlayerPawn.h +++ b/Source/M4_CPP/public/M4_PlayerPawn.h @@ -34,12 +34,8 @@ protected: UInputAction* ShootAction; UPROPERTY(VisibleAnywhere) - AM4_Projectile* Proj; - - UPROPERTY(VisibleAnywhere) - TObjectPtr Projection; + TSubclassOf Proj; - //bool HasShot = false; float MoveSpeed = 500.f; FVector2D MeshScale = FVector2D(0.6f, 0.5f); FVector2D LastMoveValue = FVector2D::ZeroVector; diff --git a/Source/M4_CPP/public/M4_Projectile.h b/Source/M4_CPP/public/M4_Projectile.h index 4bd7e08..bb81f33 100644 --- a/Source/M4_CPP/public/M4_Projectile.h +++ b/Source/M4_CPP/public/M4_Projectile.h @@ -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")