Add barebones weapon pickup
This commit is contained in:
parent
86b34b7226
commit
2d48d7c703
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,49 @@
|
||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "WeaponPickup.h"
|
||||||
|
|
||||||
|
// Sets default values
|
||||||
|
AWeaponPickup::AWeaponPickup()
|
||||||
|
{
|
||||||
|
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
||||||
|
PrimaryActorTick.bCanEverTick = true;
|
||||||
|
PrimaryActorTick.SetTickFunctionEnable(true);
|
||||||
|
PrimaryActorTick.bStartWithTickEnabled = true;
|
||||||
|
|
||||||
|
SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("SphereComponent"));
|
||||||
|
SphereComponent->SetupAttachment(RootComponent);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when the game starts or when spawned
|
||||||
|
void AWeaponPickup::BeginPlay()
|
||||||
|
{
|
||||||
|
Super::BeginPlay();
|
||||||
|
|
||||||
|
FActorSpawnParameters SpawnParameters;
|
||||||
|
SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
||||||
|
|
||||||
|
WeaponComponent = GetWorld()->SpawnActor<AWeapon>(Weapon, SpawnParameters);
|
||||||
|
|
||||||
|
FAttachmentTransformRules TransformRules = FAttachmentTransformRules(EAttachmentRule::SnapToTarget, EAttachmentRule::SnapToTarget, EAttachmentRule::SnapToTarget, true);
|
||||||
|
WeaponComponent->AttachToComponent(RootComponent, TransformRules);
|
||||||
|
WeaponComponent->SetActorRelativeLocation(FVector(0.0f, 0.0f, 5.0f));
|
||||||
|
WeaponComponent->SetActorEnableCollision(false);
|
||||||
|
|
||||||
|
WeaponStartingLocation = WeaponComponent->GetActorLocation();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called every frame
|
||||||
|
void AWeaponPickup::Tick(float DeltaTime)
|
||||||
|
{
|
||||||
|
Super::Tick(DeltaTime);
|
||||||
|
|
||||||
|
// Rotate Weapon in desired direction
|
||||||
|
WeaponComponent->AddActorLocalRotation((SpinRotation * RotationSpeed) * DeltaTime);
|
||||||
|
|
||||||
|
// Bob weapon up and down
|
||||||
|
float Time = GetWorld()->GetRealTimeSeconds();
|
||||||
|
float Sine = FMath::Sin(Time * MovementSpeed);
|
||||||
|
WeaponComponent->SetActorLocation(WeaponStartingLocation + (MovementDirection * Sine));
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Components/SphereComponent.h"
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "GameFramework/Actor.h"
|
||||||
|
#include "Weapon.h"
|
||||||
|
#include "WeaponPickup.generated.h"
|
||||||
|
|
||||||
|
UCLASS()
|
||||||
|
class NAKATOMI_API AWeaponPickup : public AActor
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||||
|
TSubclassOf<class AWeapon> Weapon;
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||||
|
FVector MovementDirection = FVector(0.0f, 1.0f, 0.0f);
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||||
|
float MovementSpeed = 1.0f;
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||||
|
FRotator SpinRotation = FRotator(0, 1, 0);
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||||
|
float RotationSpeed = 1.0f;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
USphereComponent* SphereComponent;
|
||||||
|
|
||||||
|
AWeapon* WeaponComponent;
|
||||||
|
|
||||||
|
FVector WeaponStartingLocation;
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Sets default values for this actor's properties
|
||||||
|
AWeaponPickup();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// Called when the game starts or when spawned
|
||||||
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Called every frame
|
||||||
|
virtual void Tick(float DeltaTime) override;
|
||||||
|
|
||||||
|
};
|
Loading…
Reference in New Issue