Minor - Sprite du Projectile

Le modèle 3D du projectile apparait enfin, maintenant, il faut que je puisse donner au modèle la bonne position de départ.
This commit is contained in:
NisemonoQ
2025-10-28 16:20:39 +01:00
parent 365727aa4c
commit d2968f0d36
3 changed files with 21 additions and 14 deletions

View File

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

View File

@@ -2,6 +2,7 @@
#include "GameFramework/ProjectileMovementComponent.h" #include "GameFramework/ProjectileMovementComponent.h"
#include "Components/MeshComponent.h" #include "Components/MeshComponent.h"
// Sets default values // Sets default values
AM4_Projectile::AM4_Projectile() AM4_Projectile::AM4_Projectile()
{ {
@@ -23,39 +24,45 @@ AM4_Projectile::AM4_Projectile()
{ {
ProjectileMovementComponent = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("ProjectileMovementComponent")); ProjectileMovementComponent = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("ProjectileMovementComponent"));
ProjectileMovementComponent->SetUpdatedComponent(CollisionComp); ProjectileMovementComponent->SetUpdatedComponent(CollisionComp);
ProjectileMovementComponent->InitialSpeed = 700.0f; ProjectileMovementComponent->InitialSpeed = 10.0f;
ProjectileMovementComponent->MaxSpeed = 700.0f; ProjectileMovementComponent->MaxSpeed = 10.0f;
ProjectileMovementComponent->bRotationFollowsVelocity = true; ProjectileMovementComponent->bRotationFollowsVelocity = false;
ProjectileMovementComponent->bShouldBounce = false; ProjectileMovementComponent->bShouldBounce = false;
ProjectileMovementComponent->ProjectileGravityScale = 0.0f; ProjectileMovementComponent->ProjectileGravityScale = 0.0f;
} }
if (!ProjectileMovementComponent) if (ProjectileMovementComponent)
{ {
ProjectileMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("ProjectileMeshComponent")); ProjectileMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("ProjectileMeshComponent"));
static ConstructorHelpers::FObjectFinder<UStaticMesh>Mesh(TEXT("'/Script/Engine.StaticMesh'/Game/CTP/04_Mesh/SM_Projectile.SM_Projectile'")); static ConstructorHelpers::FObjectFinder<UStaticMesh> Mesh(TEXT("/Game/CTP/04_Mesh/SM_Projectile.SM_Projectile"));
if(Mesh.Succeeded()) if(Mesh.Succeeded())
{ {
ProjectileMeshComponent->SetStaticMesh(Mesh.Object); ProjectileMeshComponent->SetStaticMesh(Mesh.Object);
} }
static ConstructorHelpers::FObjectFinder<UMaterial>Material(TEXT("'/Script/Engine.Material'/Game/CTP/05_Material/M_Player.M_Player'")); static ConstructorHelpers::FObjectFinder<UMaterial> Material(TEXT("/Game/CTP/05_Material/M_Player.M_Player"));
if (Material.Succeeded()) if (Material.Succeeded())
{ {
ProjectileMat = UMaterialInstanceDynamic::Create(Material.Object, ProjectileMeshComponent); ProjectileMat = UMaterialInstanceDynamic::Create(Material.Object, ProjectileMeshComponent);
} }
ProjectileMeshComponent->SetMaterial(0, ProjectileMat); ProjectileMeshComponent->SetMaterial(0, ProjectileMat);
ProjectileMeshComponent->SetRelativeScale3D(FVector(.2f, .2f, .2f)); ProjectileMeshComponent->SetRelativeScale3D(FVector(.2f, .2f, .25f));
ProjectileMeshComponent->SetMobility(EComponentMobility::Movable);
ProjectileMeshComponent->SetupAttachment(RootComponent); ProjectileMeshComponent->SetupAttachment(RootComponent);
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Blue, TEXT("Using the Wand!"));
} }
//InitialLifeSpan = 2.f;
} }
void AM4_Projectile::ShootDirection(const FVector& ShootDir) void AM4_Projectile::ShootDirection(const FVector& ShootDir)
{ {
ProjectileMovementComponent->Velocity = ShootDir * ProjectileMovementComponent->InitialSpeed; ProjectileMovementComponent->Velocity = -1.f * (ShootDir * ProjectileMovementComponent->InitialSpeed);
} }
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 Impulse, const FHitResult& Hit)

View File

@@ -14,8 +14,7 @@ class M4_CPP_API AM4_Projectile : public AActor
GENERATED_BODY() GENERATED_BODY()
UPROPERTY(VisibleAnywhere, Category = Movement) UPROPERTY(VisibleAnywhere, Category = Movement)
UProjectileMovementComponent* ProjectileMovementComponent; UProjectileMovementComponent* ProjectileMovementComponent;
public: public: