Major - Comportement de la Balle quasiment complet

Il ne reste plus qu'à associer le GameMode et la reconnaissance de la collision, j'ai déjà la fonction OnHit sur laquelle on peut commencer à bosser
This commit is contained in:
NisemonoQ
2025-11-01 13:05:52 +01:00
parent 9ddc2fdbed
commit 6305198eda
3 changed files with 43 additions and 27 deletions

View File

@@ -85,17 +85,18 @@ void AM4_PlayerPawn::Shoot(const FInputActionInstance& Inst)
if (Proj)
{
UWorld* World = GetWorld();
//GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Blue, TEXT("Using the Wand!"));
if (World)
{
FActorSpawnParameters SpawnParams;
SpawnParams.Owner = this;
const FVector InitialLocation = FVector(GetActorLocation().X, GetActorLocation().Y, GetActorLocation().Z);
const FVector InitialLocation = FVector(0, GetActorLocation().Y, GetActorLocation().Z);
const FRotator InitialRotation = FRotator(0.f);
AM4_Projectile* Projectile = World->SpawnActor<AM4_Projectile>(Proj, InitialLocation, InitialRotation, SpawnParams);
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Green, TEXT("Spell Casted!"));
if (Projectile)
{
Projectile->FireInDir(InitialLocation);
}
}
}
};

View File

@@ -10,17 +10,8 @@ AM4_Projectile::AM4_Projectile()
if(!RootComponent)
{
RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("ProjectileSceneComponent"));
}
if(!CollisionComp)
{
CollisionComp = CreateDefaultSubobject<UMeshComponent>(TEXT("MeshComponent"));
RootComponent = CollisionComp;
}
if (!ProjectileMeshComponent)
{
ProjectileMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("ProjectileMeshComponent"));
ProjectileMeshComponent->SetupAttachment(RootComponent);
static ConstructorHelpers::FObjectFinder<UStaticMesh> Mesh(TEXT("/Game/CTP/04_Mesh/SM_Projectile.SM_Projectile"));
if(Mesh.Succeeded())
@@ -35,18 +26,29 @@ AM4_Projectile::AM4_Projectile()
}
ProjectileMeshComponent->SetMaterial(0, ProjectileMat);
ProjectileMeshComponent->SetRelativeScale3D(FVector(.2f, .2f, .25f));
ProjectileMeshComponent->SetRelativeScale3D(FVector(.3f, .3f, .35f));
ProjectileMeshComponent->SetMobility(EComponentMobility::Movable);
ProjectileMeshComponent->SetupAttachment(RootComponent);
ProjectileMeshComponent->SetRelativeLocation(InitialLoc);
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Blue, TEXT("Using the Wand!"));
ProjectileMovementComponent = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("ProjectileMovementComponent"));
ProjectileMovementComponent->SetUpdatedComponent(CollisionComp);
ProjectileMovementComponent->InitialSpeed = 380.f;
ProjectileMovementComponent->MaxSpeed = 380.f;
ProjectileMovementComponent->bRotationFollowsVelocity = false;
ProjectileMovementComponent->bShouldBounce = false;
ProjectileMovementComponent->ProjectileGravityScale = 0.0f;
InitialLifeSpan = 10.f;
}
if(!CollisionComp)
{
CollisionComp = CreateDefaultSubobject<UMeshComponent>(TEXT("MeshComponent"));
}
}
///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::BeginPlay()
{
@@ -59,9 +61,16 @@ void AM4_Projectile::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPr
}
void AM4_Projectile::FireInDir(const FVector& ShootDir)
{
SetActorLocation(InitialLoc);
ProjectileMovementComponent->Velocity.Z = -1 * ((ShootDir.Z + 390.f) * ProjectileMovementComponent->InitialSpeed);
// ProjectileMovementComponent->Velocity.Y = InitialLoc.Y;
// ProjectileMovementComponent->Velocity.X = InitialLoc.X;
}
// Called every frame
void AM4_Projectile::Tick(float DeltaTime)
{
Super::Tick( DeltaTime);
NewLoc = InitialLoc + FVector(InitialLoc.X * Speed * DeltaTime, InitialLoc.Y * Speed * DeltaTime, InitialLoc.Z * Speed * DeltaTime);
}

View File

@@ -1,4 +1,6 @@
#pragma once
#include "GameFramework/ProjectileMovementComponent.h"
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
@@ -25,6 +27,9 @@ public:
UPROPERTY(VisibleDefaultsOnly, Category = Projectile)
UMeshComponent* CollisionComp;
UPROPERTY(VisibleAnywhere, Category = Movement)
UProjectileMovementComponent* ProjectileMovementComponent;
UPROPERTY(VisibleDefaultsOnly, Category = Projectile)
UStaticMeshComponent* ProjectileMeshComponent;
@@ -32,4 +37,5 @@ public:
UMaterialInstanceDynamic* ProjectileMat;
void OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp,FVector Impulse, const FHitResult& Hit);
void FireInDir(const FVector& ShootDir);
};