Minor - Mushroom function
J'ai ajouté une fonction au Mushroom pour enregistrer le hit de la balle lorsqu'il la touche, mais on dirait que ça ne veut pas marcher.
This commit is contained in:
@@ -31,12 +31,26 @@ AM4_Mushroom::AM4_Mushroom()
|
||||
const FVector2D MushroomScale = FVector2D(0.3f, 0.25f);
|
||||
GetStaticMeshComponent()->SetRelativeScale3D(FVector(1.f, 0.45f, 0.20f));
|
||||
|
||||
// Set collision profile to overlap all
|
||||
GetStaticMeshComponent()->SetCollisionProfileName(TEXT("OverlapAll"));
|
||||
// Set collision profile to block all
|
||||
GetStaticMeshComponent()->SetCollisionProfileName(TEXT("BlockAll"));
|
||||
|
||||
}
|
||||
|
||||
void AM4_Mushroom::BeginPlay()
|
||||
{
|
||||
MushLife = 3;
|
||||
DestructionHit = 0;
|
||||
Super::BeginPlay();
|
||||
}
|
||||
|
||||
void AM4_Mushroom::OnHit(UPrimitiveComponent* HitComp,AActor* OtherActor,UPrimitiveComponent* OtherComp,FVector NormalImpulse,const FHitResult& Hit)
|
||||
{
|
||||
if (OtherActor != this)
|
||||
{
|
||||
DestructionHit++;
|
||||
if (DestructionHit == MushLife)
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@ AM4_PlayerPawn::AM4_PlayerPawn()
|
||||
void AM4_PlayerPawn::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
SetActorLocation(FVector(0.0f, 0.0f, -400.0f));
|
||||
SetActorLocation(FVector(-400.0f, 0.0f, -400.0f));
|
||||
}
|
||||
|
||||
void AM4_PlayerPawn::Tick(float DeltaTime)
|
||||
@@ -90,7 +90,7 @@ void AM4_PlayerPawn::Shoot(const FInputActionInstance& Inst)
|
||||
{
|
||||
FActorSpawnParameters SpawnParams;
|
||||
SpawnParams.Owner = this;
|
||||
const FVector InitialLocation = FVector(0, GetActorLocation().Y, GetActorLocation().Z);
|
||||
const FVector InitialLocation = FVector(-400.f, GetActorLocation().Y, GetActorLocation().Z);
|
||||
const FRotator InitialRotation = FRotator(0.f);
|
||||
AM4_Projectile* Projectile = World->SpawnActor<AM4_Projectile>(Proj, InitialLocation, InitialRotation, SpawnParams);
|
||||
if (Projectile)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "M4_Projectile.h"
|
||||
#include "Components/MeshComponent.h"
|
||||
#include "M4_Gamemode.h"
|
||||
#include "M4_Mushroom.h"
|
||||
|
||||
// Sets default values
|
||||
AM4_Projectile::AM4_Projectile()
|
||||
@@ -11,7 +12,7 @@ AM4_Projectile::AM4_Projectile()
|
||||
{
|
||||
RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("ProjectileSceneComponent"));
|
||||
ProjectileMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("ProjectileMeshComponent"));
|
||||
ProjectileMeshComponent->SetupAttachment(RootComponent);
|
||||
ProjectileMeshComponent->SetupAttachment(RootComponent);
|
||||
|
||||
static ConstructorHelpers::FObjectFinder<UStaticMesh> Mesh(TEXT("/Game/CTP/04_Mesh/SM_Projectile.SM_Projectile"));
|
||||
if(Mesh.Succeeded())
|
||||
@@ -26,7 +27,7 @@ AM4_Projectile::AM4_Projectile()
|
||||
}
|
||||
|
||||
ProjectileMeshComponent->SetMaterial(0, ProjectileMat);
|
||||
ProjectileMeshComponent->SetRelativeScale3D(FVector(.3f, .3f, .35f));
|
||||
ProjectileMeshComponent->SetRelativeScale3D(FVector(.8f, .3f, .35f));
|
||||
ProjectileMeshComponent->SetMobility(EComponentMobility::Movable);
|
||||
ProjectileMeshComponent->SetRelativeLocation(InitialLoc);
|
||||
|
||||
@@ -45,6 +46,7 @@ AM4_Projectile::AM4_Projectile()
|
||||
{
|
||||
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.
|
||||
@@ -56,17 +58,26 @@ void AM4_Projectile::BeginPlay()
|
||||
InitialLoc = GetActorLocation();
|
||||
}
|
||||
|
||||
void AM4_Projectile::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp,FVector Impulse, const FHitResult& Hit)
|
||||
void AM4_Projectile::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
|
||||
{
|
||||
|
||||
if (OtherActor && OtherActor != this && OtherComp != nullptr)
|
||||
{
|
||||
AM4_Mushroom* Mushroom = Cast<AM4_Mushroom>(OtherActor);
|
||||
if (Mushroom)
|
||||
{
|
||||
Mushroom->OnHit(HitComp,OtherActor,OtherComp,NormalImpulse,Hit);
|
||||
}
|
||||
|
||||
Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
void AM4_Projectile::FireInDir(const FVector& ShootDir)
|
||||
{
|
||||
SetActorLocation(InitialLoc);
|
||||
ProjectileMovementComponent->Velocity.Z = -1 * ((ShootDir.Z + 390.f) * ProjectileMovementComponent->InitialSpeed);
|
||||
ProjectileMovementComponent->Velocity.Z = -1 * ((ShootDir.Z + 380.f) * ProjectileMovementComponent->InitialSpeed);
|
||||
// ProjectileMovementComponent->Velocity.Y = InitialLoc.Y;
|
||||
// ProjectileMovementComponent->Velocity.X = InitialLoc.X;
|
||||
ProjectileMovementComponent->Velocity.X = 0.f;
|
||||
}
|
||||
|
||||
// Called every frame
|
||||
|
||||
@@ -13,9 +13,14 @@ class M4_CPP_API AM4_Mushroom : public AStaticMeshActor
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
// Sets default values for this pawn's properties
|
||||
AM4_Mushroom();
|
||||
|
||||
|
||||
int MushLife;
|
||||
int DestructionHit = 0;
|
||||
|
||||
UFUNCTION()
|
||||
void OnHit(UPrimitiveComponent* HitComp,AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse,const FHitResult& Hit);
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
};
|
||||
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
virtual void Tick( float DeltaTime ) override;
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
float Speed = 1.f;
|
||||
bool CollisionCheck = false;
|
||||
FVector InitialLoc;
|
||||
FVector NewLoc;
|
||||
|
||||
@@ -35,7 +35,8 @@ public:
|
||||
|
||||
UPROPERTY(VisibleDefaultsOnly, Category = Projectile)
|
||||
UMaterialInstanceDynamic* ProjectileMat;
|
||||
|
||||
void OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp,FVector Impulse, const FHitResult& Hit);
|
||||
|
||||
UFUNCTION()
|
||||
void OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit);
|
||||
void FireInDir(const FVector& ShootDir);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user