From 49685ed1678f64bbbf7cdd183c876b1fabf882ef Mon Sep 17 00:00:00 2001 From: NisemonoQ Date: Fri, 31 Oct 2025 16:16:53 +0100 Subject: [PATCH] Minor - Nouveau comportement pour la Balle MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit La Balle devrait pouvoir directement se déplacer et avoir son mesh qui spawne aussi --- Source/M4_CPP/private/M4_PlayerPawn.cpp | 9 +++--- Source/M4_CPP/private/M4_Projectile.cpp | 43 ++++++++++++------------- Source/M4_CPP/public/M4_Projectile.h | 10 +++--- 3 files changed, 30 insertions(+), 32 deletions(-) diff --git a/Source/M4_CPP/private/M4_PlayerPawn.cpp b/Source/M4_CPP/private/M4_PlayerPawn.cpp index d145f58..884f3cc 100644 --- a/Source/M4_CPP/private/M4_PlayerPawn.cpp +++ b/Source/M4_CPP/private/M4_PlayerPawn.cpp @@ -97,13 +97,12 @@ 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) + GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Green, TEXT("Spell Casted!")); + //FVector LaunchDirection = FVector(InitialLocation); + /*if (Projectile) { Projectile->ShootDirection(LaunchDirection); - GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Green, TEXT("Spell Casted!")); - } + }*/ } } diff --git a/Source/M4_CPP/private/M4_Projectile.cpp b/Source/M4_CPP/private/M4_Projectile.cpp index c1920dc..4780997 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,19 +20,7 @@ AM4_Projectile::AM4_Projectile() RootComponent = CollisionComp; } - - if(!ProjectileMovementComponent) - { - ProjectileMovementComponent = CreateDefaultSubobject(TEXT("ProjectileMovementComponent")); - ProjectileMovementComponent->SetUpdatedComponent(CollisionComp); - ProjectileMovementComponent->InitialSpeed = 10.0f; - ProjectileMovementComponent->MaxSpeed = 10.0f; - ProjectileMovementComponent->bRotationFollowsVelocity = false; - ProjectileMovementComponent->bShouldBounce = false; - ProjectileMovementComponent->ProjectileGravityScale = 0.0f; - } - - if (ProjectileMovementComponent) + if (!ProjectileMeshComponent) { ProjectileMeshComponent = CreateDefaultSubobject(TEXT("ProjectileMeshComponent")); @@ -53,26 +42,34 @@ AM4_Projectile::AM4_Projectile() ProjectileMeshComponent->SetupAttachment(RootComponent); GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Blue, TEXT("Using the Wand!")); - } - //InitialLifeSpan = 2.f; - + ///FAIRE SUPER GAFFE AUX INDENTATIONS ET LES FOR LOOPS sont à bien faire. + ///Ce qui est critique dans notre code doit être vraiment bien mis en évidence sans être obscurci par la boucle. + ///Gestion des pointeurs à revoir, lisibilité des fonctions critiques + } } -void AM4_Projectile::ShootDirection(const FVector& ShootDir) +/*void AM4_Projectile::ShootDirection(const FVector& ShootDir) { - ProjectileMovementComponent->Velocity = -1.f * (ShootDir * ProjectileMovementComponent->InitialSpeed); - + FVector Dir = -1.f *(ShootDir * Speed); +}*/ + + +void AM4_Projectile::OnHit( +* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp,FVector Impulse, const FHitResult& Hit) +{ + } -void AM4_Projectile::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector Impulse, const FHitResult& Hit) +void AM4_Projectile::BeginPlay() { - //OtherComp->AddImpulseAtLocation(GetVelocity() * BulletSpeed, GetActorLocation()); + Super::BeginPlay(); + InitialLoc = GetActorLocation(); } // Called every frame void AM4_Projectile::Tick( float DeltaTime ) { - Super::Tick( DeltaTime ); - + Super::Tick( DeltaTime); + //NewLoc = GetActorLocation() + FVector(0.f, InitialLoc.Y * Speed * DeltaTime, InitialLoc.Z * Speed * 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..147d115 100644 --- a/Source/M4_CPP/public/M4_Projectile.h +++ b/Source/M4_CPP/public/M4_Projectile.h @@ -13,14 +13,16 @@ class M4_CPP_API AM4_Projectile : public AActor { GENERATED_BODY() - UPROPERTY(VisibleAnywhere, Category = Movement) - UProjectileMovementComponent* ProjectileMovementComponent; - public: AM4_Projectile(); virtual void Tick( float DeltaTime ) override; + virtual void BeginPlay() override; + + float Speed = 1.f; + FVector InitialLoc; + FVector NewLoc; UPROPERTY(VisibleDefaultsOnly, Category = Projectile) UMeshComponent* CollisionComp; @@ -28,7 +30,7 @@ public: UPROPERTY(VisibleDefaultsOnly, Category = Projectile) UStaticMeshComponent* ProjectileMeshComponent; - UPROPERTY(VisibleDefaultsOnly, Category = Movement) + UPROPERTY(VisibleDefaultsOnly, Category = Projectile) UMaterialInstanceDynamic* ProjectileMat; void ShootDirection(const FVector& ShootDir);