Minor - Petit changement pour le spawn des balles

This commit is contained in:
NisemonoQ
2025-10-30 22:00:07 +01:00
parent d2968f0d36
commit 406bafff0a
4 changed files with 27 additions and 17 deletions

1
.idea/.idea.M4_CPP.dir/.idea/.name generated Normal file
View File

@@ -0,0 +1 @@
M4_CPP

View File

@@ -97,6 +97,7 @@ void AM4_PlayerPawn::Shoot(const FInputActionInstance& Inst)
const FRotator InitialRotation = FRotator(0.f);
AM4_Projectile* Projectile = World->SpawnActor<AM4_Projectile>(Proj, InitialLocation, InitialRotation, SpawnParams);
FVector LaunchDirection = FVector(InitialLocation);
if (Projectile)

View File

@@ -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<UProjectileMovementComponent>(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<UStaticMeshComponent>(TEXT("ProjectileMeshComponent"));
static ConstructorHelpers::FObjectFinder<UStaticMesh> 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<UMaterial> 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 );
}

View File

@@ -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);