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.
87 lines
2.9 KiB
C++
87 lines
2.9 KiB
C++
#include "M4_Projectile.h"
|
|
#include "Components/MeshComponent.h"
|
|
#include "M4_Gamemode.h"
|
|
#include "M4_Mushroom.h"
|
|
|
|
// Sets default values
|
|
AM4_Projectile::AM4_Projectile()
|
|
{
|
|
PrimaryActorTick.bCanEverTick = true;
|
|
|
|
if(!RootComponent)
|
|
{
|
|
RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("ProjectileSceneComponent"));
|
|
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())
|
|
{
|
|
ProjectileMeshComponent->SetStaticMesh(Mesh.Object);
|
|
}
|
|
|
|
static ConstructorHelpers::FObjectFinder<UMaterial> Material(TEXT("/Game/CTP/05_Material/M_Player.M_Player"));
|
|
if (Material.Succeeded())
|
|
{
|
|
ProjectileMat = UMaterialInstanceDynamic::Create(Material.Object, ProjectileMeshComponent);
|
|
}
|
|
|
|
ProjectileMeshComponent->SetMaterial(0, ProjectileMat);
|
|
ProjectileMeshComponent->SetRelativeScale3D(FVector(.8f, .3f, .35f));
|
|
ProjectileMeshComponent->SetMobility(EComponentMobility::Movable);
|
|
ProjectileMeshComponent->SetRelativeLocation(InitialLoc);
|
|
|
|
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()
|
|
{
|
|
Super::BeginPlay();
|
|
InitialLoc = GetActorLocation();
|
|
}
|
|
|
|
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 + 380.f) * ProjectileMovementComponent->InitialSpeed);
|
|
// ProjectileMovementComponent->Velocity.Y = InitialLoc.Y;
|
|
ProjectileMovementComponent->Velocity.X = 0.f;
|
|
}
|
|
|
|
// Called every frame
|
|
void AM4_Projectile::Tick(float DeltaTime)
|
|
{
|
|
Super::Tick( DeltaTime);
|
|
} |