Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Fill out your copyright notice in the Description page of Project Settings.
- #include "Items/Item.h"
- #include "Slash/DebugMacros.h"
- #include "Components/SphereComponent.h"
- #include "Characters/SlashCharacter.h"
- //#define THIRTY 30
- // Sets default values
- AItem::AItem()
- {
- // 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;
- ItemMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("ItemMeshComponent"));
- RootComponent = ItemMesh;
- Sphere = CreateDefaultSubobject<USphereComponent>(TEXT("Sphere"));
- Sphere->SetupAttachment(GetRootComponent());
- }
- // Called when the game starts or when spawned
- void AItem::BeginPlay()
- {
- Super::BeginPlay();
- Sphere->OnComponentBeginOverlap.AddDynamic(this, &AItem::OnSphereOverlap);
- Sphere->OnComponentEndOverlap.AddDynamic(this, &AItem::OnSphereEndOverlap);
- }
- float AItem::TransformedSin()
- {
- return Amplitude * FMath::Sin(RuningTime * TimeConstant);
- }
- float AItem::TransformCos()
- {
- return Amplitude * FMath::Cos(RuningTime * TimeConstant);
- }
- void AItem::OnSphereOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
- {
- //const FString OtherActorName = OtherActor->GetName();
- ASlashCharacter* SlashCharacter = Cast<ASlashCharacter>(OtherActor);
- if (SlashCharacter)
- {
- SlashCharacter->SetOverlappingItem(this);
- }
- }
- void AItem::OnSphereEndOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
- {
- ASlashCharacter* SlashCharacter = Cast<ASlashCharacter>(OtherActor);
- if (SlashCharacter)
- {
- SlashCharacter->SetOverlappingItem(nullptr);
- }
- /*
- const FString OtherActorName = FString("Exit overlap with:") + OtherActor->GetName();
- if (GEngine)
- {
- GEngine->AddOnScreenDebugMessage(1, 30.f, FColor::Blue, OtherActorName);
- }
- */
- }
- // Called every frame
- void AItem::Tick(float DeltaTime)
- {
- Super::Tick(DeltaTime);
- RuningTime += DeltaTime;
- /*
- const float Z = TransformedSin();
- AddActorWorldOffset(FVector(0.f,0.f,Z));
- */
- if (ItemState == EItemState::EIS_Hovering)
- {
- AddActorWorldOffset(FVector(0.f, 0.f, TransformedSin()));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement