Minor - Apparition du sprite du tir
Normalement, le spirte apparait bien lors de l'appui sur la touche espace
This commit is contained in:
@@ -89,16 +89,17 @@ void AM4_PlayerPawn::Shoot(const FInputActionInstance& Inst)
|
|||||||
{
|
{
|
||||||
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, TEXT("Using the Wand!"));
|
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, TEXT("Using the Wand!"));
|
||||||
UWorld* const World = GetWorld();
|
UWorld* const World = GetWorld();
|
||||||
if (World !=nullptr && Proj != nullptr)
|
if (!Proj && !World)
|
||||||
{
|
{
|
||||||
FVector TargetPosition = FVector3d(GetActorLocation().X, GetActorLocation().Y, GetActorLocation().Z);
|
FVector TargetPosition = GetActorLocation();
|
||||||
|
FRotator SpawnRotation = GetActorRotation();
|
||||||
FRotator SpawnRotation = UKismetMathLibrary::FindLookAtRotation(FVector3d(0), TargetPosition);
|
|
||||||
|
|
||||||
FActorSpawnParameters ActorSpawnParams;
|
FActorSpawnParameters ActorSpawnParams;
|
||||||
ActorSpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButDontSpawnIfColliding;
|
ActorSpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButDontSpawnIfColliding;
|
||||||
|
ActorSpawnParams.Owner = this;
|
||||||
|
|
||||||
Projection = GetWorld()->SpawnActor<AM4_Projectile>(TargetPosition, SpawnRotation, ActorSpawnParams);
|
GetWorld()->SpawnActor<AM4_Projectile>(Proj, TargetPosition, SpawnRotation, ActorSpawnParams);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,14 +8,15 @@
|
|||||||
// Sets default values
|
// Sets default values
|
||||||
AM4_Projectile::AM4_Projectile()
|
AM4_Projectile::AM4_Projectile()
|
||||||
{
|
{
|
||||||
MeshComp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MeshComp"));
|
ProjectileMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MeshComp"));
|
||||||
MeshComp-> SetRelativeScale3D(FVector(1.f, .1f,.1f));
|
ProjectileMesh-> SetRelativeScale3D(FVector(1.f, .1f,.1f));
|
||||||
MeshComp->BodyInstance.SetCollisionProfileName(TEXT("Projectile"));
|
ProjectileMesh->BodyInstance.SetCollisionProfileName(TEXT("Projectile"));
|
||||||
MeshComp->OnComponentHit.AddDynamic(this, &AM4_Projectile::OnHit);
|
ProjectileMesh->OnComponentHit.AddDynamic(this, &AM4_Projectile::OnHit);
|
||||||
|
ProjectileMesh->SetupAttachment(RootComponent);
|
||||||
|
ProjectileMesh->SetMobility(EComponentMobility::Movable);
|
||||||
|
ProjectileMesh->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
|
||||||
|
|
||||||
|
|
||||||
MeshComp->SetupAttachment(RootComponent);
|
|
||||||
MeshComp->SetMobility(EComponentMobility::Movable);
|
|
||||||
MeshComp->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
|||||||
@@ -34,12 +34,8 @@ protected:
|
|||||||
UInputAction* ShootAction;
|
UInputAction* ShootAction;
|
||||||
|
|
||||||
UPROPERTY(VisibleAnywhere)
|
UPROPERTY(VisibleAnywhere)
|
||||||
AM4_Projectile* Proj;
|
TSubclassOf<AM4_Projectile> Proj;
|
||||||
|
|
||||||
UPROPERTY(VisibleAnywhere)
|
|
||||||
TObjectPtr<AM4_Projectile> Projection;
|
|
||||||
|
|
||||||
//bool HasShot = false;
|
|
||||||
float MoveSpeed = 500.f;
|
float MoveSpeed = 500.f;
|
||||||
FVector2D MeshScale = FVector2D(0.6f, 0.5f);
|
FVector2D MeshScale = FVector2D(0.6f, 0.5f);
|
||||||
FVector2D LastMoveValue = FVector2D::ZeroVector;
|
FVector2D LastMoveValue = FVector2D::ZeroVector;
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public:
|
|||||||
|
|
||||||
// Despawn after 5 seconds by default
|
// Despawn after 5 seconds by default
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Projectile | Lifespan")
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Projectile | Lifespan")
|
||||||
float ProjectileLifespan = 5.0f;
|
float ProjectileLifespan = 3.0f;
|
||||||
|
|
||||||
// The amount of force this projectile imparts on objects it collides with
|
// The amount of force this projectile imparts on objects it collides with
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Projectile | Physics")
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Projectile | Physics")
|
||||||
|
|||||||
Reference in New Issue
Block a user