Fix static mesh inhabiting the incorrect position

This commit is contained in:
baz 2024-03-12 19:56:17 +00:00
parent e2e32e0092
commit 1b32434d98
1 changed files with 4 additions and 5 deletions

View File

@ -15,8 +15,7 @@ void AStaticMeshPickup::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
StaticMeshComponent->SetWorldLocation(this->GetActorLocation()); StartingLocation = StaticMeshComponent->GetRelativeLocation();
StartingLocation = this->GetActorLocation();
StaticMeshComponent->SetCollisionProfileName(FName("NoCollision")); StaticMeshComponent->SetCollisionProfileName(FName("NoCollision"));
} }
@ -26,10 +25,10 @@ void AStaticMeshPickup::Tick(float DeltaTime)
if (StaticMeshComponent) if (StaticMeshComponent)
{ {
// Rotate Weapon in desired direction // Rotate StaticMesh in desired direction
StaticMeshComponent->AddLocalRotation((SpinRotation * RotationSpeed) * DeltaTime); StaticMeshComponent->AddLocalRotation((SpinRotation * RotationSpeed) * DeltaTime);
// Bob weapon up and down // Bob StaticMesh up and down
const float Time = GetWorld()->GetRealTimeSeconds(); const float Time = GetWorld()->GetRealTimeSeconds();
const float Sine = FMath::Abs(FMath::Sin(Time * MovementSpeed)); const float Sine = FMath::Abs(FMath::Sin(Time * MovementSpeed));
StaticMeshComponent->SetRelativeLocation(StartingLocation + ((MovementDirection * Sine) * MovementDistance)); StaticMeshComponent->SetRelativeLocation(StartingLocation + ((MovementDirection * Sine) * MovementDistance));