Advertisement
Dieton

Item.cpp

Dec 13th, 2023 (edited)
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.32 KB | Gaming | 0 0
  1. // Fill out your copyright notice in the Description page of Project Settings.
  2.  
  3.  
  4. #include "Items/Item.h"
  5.  
  6. #include "Slash/DebugMacros.h"
  7. #include "Components/SphereComponent.h"
  8. #include "Characters/SlashCharacter.h"
  9. //#define THIRTY 30
  10.  
  11.  
  12. // Sets default values
  13. AItem::AItem()
  14. {
  15.     // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
  16.     PrimaryActorTick.bCanEverTick = true;
  17.  
  18.     ItemMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("ItemMeshComponent"));
  19.     RootComponent = ItemMesh;
  20.  
  21.     Sphere = CreateDefaultSubobject<USphereComponent>(TEXT("Sphere"));
  22.     Sphere->SetupAttachment(GetRootComponent());
  23.  
  24. }
  25.  
  26. // Called when the game starts or when spawned
  27. void AItem::BeginPlay()
  28. {
  29.     Super::BeginPlay();
  30.  
  31.     Sphere->OnComponentBeginOverlap.AddDynamic(this, &AItem::OnSphereOverlap);
  32.     Sphere->OnComponentEndOverlap.AddDynamic(this, &AItem::OnSphereEndOverlap);
  33. }
  34.  
  35. float AItem::TransformedSin()
  36. {
  37.     return Amplitude * FMath::Sin(RuningTime * TimeConstant);
  38. }
  39.  
  40. float AItem::TransformCos()
  41. {
  42.     return Amplitude * FMath::Cos(RuningTime * TimeConstant);
  43. }
  44.  
  45. void AItem::OnSphereOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
  46. {
  47.     //const FString OtherActorName = OtherActor->GetName();
  48.     ASlashCharacter* SlashCharacter = Cast<ASlashCharacter>(OtherActor);
  49.     if (SlashCharacter)
  50.     {
  51.         SlashCharacter->SetOverlappingItem(this);
  52.     }
  53. }
  54.  
  55. void AItem::OnSphereEndOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
  56. {
  57.     ASlashCharacter* SlashCharacter = Cast<ASlashCharacter>(OtherActor);
  58.     if (SlashCharacter)
  59.     {
  60.         SlashCharacter->SetOverlappingItem(nullptr);
  61.     }
  62.  
  63.     /*
  64.     const FString OtherActorName = FString("Exit overlap with:") + OtherActor->GetName();
  65.     if (GEngine)
  66.     {
  67.         GEngine->AddOnScreenDebugMessage(1, 30.f, FColor::Blue, OtherActorName);
  68.     }
  69.     */
  70. }
  71.  
  72. // Called every frame
  73. void AItem::Tick(float DeltaTime)
  74. {
  75.     Super::Tick(DeltaTime);
  76.     RuningTime += DeltaTime;
  77.  
  78.     /*
  79.     const float Z = TransformedSin();
  80.     AddActorWorldOffset(FVector(0.f,0.f,Z));
  81.     */
  82.     if (ItemState == EItemState::EIS_Hovering)
  83.     {
  84.         AddActorWorldOffset(FVector(0.f, 0.f, TransformedSin()));
  85.     }
  86.    
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement