diff --git a/Source/M4_CPP/private/M4_PlayerPawn.cpp b/Source/M4_CPP/private/M4_PlayerPawn.cpp index c9a6c28..d145f58 100644 --- a/Source/M4_CPP/private/M4_PlayerPawn.cpp +++ b/Source/M4_CPP/private/M4_PlayerPawn.cpp @@ -87,16 +87,17 @@ void AM4_PlayerPawn::Shoot(const FInputActionInstance& Inst) if (Proj) { 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) { FActorSpawnParameters SpawnParams; 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(Proj, InitialLocation, FRotator(), SpawnParams); - FVector LaunchDirection = FVector(0.0f, InitialLocation.Y + 1.f,InitialLocation.Z); + AM4_Projectile* Projectile = World->SpawnActor(Proj, InitialLocation, InitialRotation, SpawnParams); + FVector LaunchDirection = FVector(InitialLocation); if (Projectile) { diff --git a/Source/M4_CPP/private/M4_Projectile.cpp b/Source/M4_CPP/private/M4_Projectile.cpp index 894a635..c1920dc 100644 --- a/Source/M4_CPP/private/M4_Projectile.cpp +++ b/Source/M4_CPP/private/M4_Projectile.cpp @@ -2,6 +2,7 @@ #include "GameFramework/ProjectileMovementComponent.h" #include "Components/MeshComponent.h" + // Sets default values AM4_Projectile::AM4_Projectile() { @@ -23,39 +24,45 @@ AM4_Projectile::AM4_Projectile() { ProjectileMovementComponent = CreateDefaultSubobject(TEXT("ProjectileMovementComponent")); ProjectileMovementComponent->SetUpdatedComponent(CollisionComp); - ProjectileMovementComponent->InitialSpeed = 700.0f; - ProjectileMovementComponent->MaxSpeed = 700.0f; - ProjectileMovementComponent->bRotationFollowsVelocity = true; + ProjectileMovementComponent->InitialSpeed = 10.0f; + ProjectileMovementComponent->MaxSpeed = 10.0f; + ProjectileMovementComponent->bRotationFollowsVelocity = false; ProjectileMovementComponent->bShouldBounce = false; ProjectileMovementComponent->ProjectileGravityScale = 0.0f; } - if (!ProjectileMovementComponent) + if (ProjectileMovementComponent) { ProjectileMeshComponent = CreateDefaultSubobject(TEXT("ProjectileMeshComponent")); - static ConstructorHelpers::FObjectFinderMesh(TEXT("'/Script/Engine.StaticMesh'/Game/CTP/04_Mesh/SM_Projectile.SM_Projectile'")); + static ConstructorHelpers::FObjectFinder Mesh(TEXT("/Game/CTP/04_Mesh/SM_Projectile.SM_Projectile")); if(Mesh.Succeeded()) { ProjectileMeshComponent->SetStaticMesh(Mesh.Object); } - static ConstructorHelpers::FObjectFinderMaterial(TEXT("'/Script/Engine.Material'/Game/CTP/05_Material/M_Player.M_Player'")); + static ConstructorHelpers::FObjectFinder 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(.2f, .2f, .2f)); + ProjectileMeshComponent->SetRelativeScale3D(FVector(.2f, .2f, .25f)); + ProjectileMeshComponent->SetMobility(EComponentMobility::Movable); ProjectileMeshComponent->SetupAttachment(RootComponent); + + GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Blue, TEXT("Using the Wand!")); } + //InitialLifeSpan = 2.f; + } 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) diff --git a/Source/M4_CPP/public/M4_Projectile.h b/Source/M4_CPP/public/M4_Projectile.h index 1c5b982..6bafede 100644 --- a/Source/M4_CPP/public/M4_Projectile.h +++ b/Source/M4_CPP/public/M4_Projectile.h @@ -14,8 +14,7 @@ class M4_CPP_API AM4_Projectile : public AActor GENERATED_BODY() UPROPERTY(VisibleAnywhere, Category = Movement) - UProjectileMovementComponent* ProjectileMovementComponent; - + UProjectileMovementComponent* ProjectileMovementComponent; public: