From 406bafff0a810f5ce7c8420add1effbd7d9bdbee Mon Sep 17 00:00:00 2001 From: NisemonoQ Date: Thu, 30 Oct 2025 22:00:07 +0100 Subject: [PATCH] Minor - Petit changement pour le spawn des balles --- .idea/.idea.M4_CPP.dir/.idea/.name | 1 + Source/M4_CPP/private/M4_PlayerPawn.cpp | 1 + Source/M4_CPP/private/M4_Projectile.cpp | 32 +++++++++++++++---------- Source/M4_CPP/public/M4_Projectile.h | 10 ++++---- 4 files changed, 27 insertions(+), 17 deletions(-) create mode 100644 .idea/.idea.M4_CPP.dir/.idea/.name diff --git a/.idea/.idea.M4_CPP.dir/.idea/.name b/.idea/.idea.M4_CPP.dir/.idea/.name new file mode 100644 index 0000000..4857ff5 --- /dev/null +++ b/.idea/.idea.M4_CPP.dir/.idea/.name @@ -0,0 +1 @@ +M4_CPP \ No newline at end of file diff --git a/Source/M4_CPP/private/M4_PlayerPawn.cpp b/Source/M4_CPP/private/M4_PlayerPawn.cpp index d145f58..59c7b4a 100644 --- a/Source/M4_CPP/private/M4_PlayerPawn.cpp +++ b/Source/M4_CPP/private/M4_PlayerPawn.cpp @@ -97,6 +97,7 @@ void AM4_PlayerPawn::Shoot(const FInputActionInstance& Inst) const FRotator InitialRotation = FRotator(0.f); AM4_Projectile* Projectile = World->SpawnActor(Proj, InitialLocation, InitialRotation, SpawnParams); + FVector LaunchDirection = FVector(InitialLocation); if (Projectile) diff --git a/Source/M4_CPP/private/M4_Projectile.cpp b/Source/M4_CPP/private/M4_Projectile.cpp index c1920dc..8da97cd 100644 --- a/Source/M4_CPP/private/M4_Projectile.cpp +++ b/Source/M4_CPP/private/M4_Projectile.cpp @@ -6,6 +6,7 @@ // Sets default values AM4_Projectile::AM4_Projectile() { + PrimaryActorTick.bCanEverTick = true; if(!RootComponent) @@ -19,7 +20,6 @@ AM4_Projectile::AM4_Projectile() RootComponent = CollisionComp; } - if(!ProjectileMovementComponent) { ProjectileMovementComponent = CreateDefaultSubobject(TEXT("ProjectileMovementComponent")); @@ -29,17 +29,20 @@ AM4_Projectile::AM4_Projectile() ProjectileMovementComponent->bRotationFollowsVelocity = false; ProjectileMovementComponent->bShouldBounce = false; ProjectileMovementComponent->ProjectileGravityScale = 0.0f; + + LastMove = GetActorLocation(); } - if (ProjectileMovementComponent) - { + if (!ProjectileMeshComponent) + { ProjectileMeshComponent = CreateDefaultSubobject(TEXT("ProjectileMeshComponent")); static ConstructorHelpers::FObjectFinder Mesh(TEXT("/Game/CTP/04_Mesh/SM_Projectile.SM_Projectile")); - if(Mesh.Succeeded()) - { - ProjectileMeshComponent->SetStaticMesh(Mesh.Object); - } + if(Mesh.Succeeded()) + { + ProjectileMeshComponent->SetStaticMesh(Mesh.Object); + GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Blue, TEXT("Using the Wand!")); + } static ConstructorHelpers::FObjectFinder Material(TEXT("/Game/CTP/05_Material/M_Player.M_Player")); if (Material.Succeeded()) @@ -49,20 +52,24 @@ AM4_Projectile::AM4_Projectile() ProjectileMeshComponent->SetMaterial(0, ProjectileMat); ProjectileMeshComponent->SetRelativeScale3D(FVector(.2f, .2f, .25f)); + //ProjectileMeshComponent->SetRelativeLocation(); ProjectileMeshComponent->SetMobility(EComponentMobility::Movable); ProjectileMeshComponent->SetupAttachment(RootComponent); - - GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Blue, TEXT("Using the Wand!")); } - //InitialLifeSpan = 2.f; - +} + + +void AM4_Projectile::BeginPlay() +{ + Super::BeginPlay(); + LastMove = GetActorLocation(); + SetActorLocation(LastMove); } void AM4_Projectile::ShootDirection(const FVector& ShootDir) { ProjectileMovementComponent->Velocity = -1.f * (ShootDir * ProjectileMovementComponent->InitialSpeed); - } void AM4_Projectile::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector Impulse, const FHitResult& Hit) @@ -74,5 +81,4 @@ void AM4_Projectile::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPr void AM4_Projectile::Tick( float DeltaTime ) { Super::Tick( DeltaTime ); - } \ No newline at end of file diff --git a/Source/M4_CPP/public/M4_Projectile.h b/Source/M4_CPP/public/M4_Projectile.h index 6bafede..43a8936 100644 --- a/Source/M4_CPP/public/M4_Projectile.h +++ b/Source/M4_CPP/public/M4_Projectile.h @@ -13,24 +13,26 @@ class M4_CPP_API AM4_Projectile : public AActor { GENERATED_BODY() - UPROPERTY(VisibleAnywhere, Category = Movement) - UProjectileMovementComponent* ProjectileMovementComponent; - public: AM4_Projectile(); + virtual void BeginPlay() override; virtual void Tick( float DeltaTime ) override; UPROPERTY(VisibleDefaultsOnly, Category = Projectile) UMeshComponent* CollisionComp; + + UPROPERTY(VisibleAnywhere, Category = Movement) + UProjectileMovementComponent* ProjectileMovementComponent; UPROPERTY(VisibleDefaultsOnly, Category = Projectile) UStaticMeshComponent* ProjectileMeshComponent; UPROPERTY(VisibleDefaultsOnly, Category = Movement) UMaterialInstanceDynamic* ProjectileMat; - + + FVector LastMove = FVector::ZeroVector; void ShootDirection(const FVector& ShootDir); void OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp,FVector Impulse, const FHitResult& Hit);