Guest User

MyActor.cpp

a guest
Jun 2nd, 2016
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. // Fill out your copyright notice in the Description page of Project Settings.
  2.  
  3. #include "UnrealTutorial.h"
  4. #include "MyActor.h"
  5.  
  6.  
  7. // Sets default values
  8. AMyActor::AMyActor()
  9. {
  10. // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
  11. PrimaryActorTick.bCanEverTick = true;
  12.  
  13. tBox = CreateDefaultSubobject<UBoxComponent>(TEXT("Root"));
  14.  
  15. tBox->bGenerateOverlapEvents = true;
  16.  
  17. tBox->OnComponentBeginOverlap.AddDynamic(this, &AMyActor::TriggerEnter);
  18.  
  19. tBox->SetRelativeScale3D(BoxSize);
  20.  
  21. RootComponent = tBox;
  22.  
  23. MyMesh = CreateAbstractDefaultSubobject<UStaticMeshComponent>(TEXT("MyMesh"));
  24.  
  25. MyMesh->AttachTo(RootComponent);
  26.  
  27. SpeedScale = 0.0f;
  28.  
  29. }
  30.  
  31. // Called when the game starts or when spawned
  32. void AMyActor::BeginPlay()
  33. {
  34. Super::BeginPlay();
  35.  
  36. }
  37.  
  38. // Called every frame
  39. void AMyActor::Tick( float DeltaTime )
  40. {
  41. Super::Tick( DeltaTime );
  42.  
  43. FVector NewLocation = GetActorLocation();
  44.  
  45. float DeltaHeight = (FMath::Sin(RunningTime + DeltaTime) - FMath::Sin(RunningTime)); //bounces the object between 0 and -1
  46. //when the obj goes to 0 it starts to move down. when the obj goes to -1 it starts to move up
  47.  
  48. NewLocation.X += DeltaHeight *SpeedScale;
  49. RunningTime += DeltaTime;
  50. SetActorLocation(NewLocation);
  51. }
  52.  
  53.  
  54. void AMyActor::TriggerEnter(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
  55. {
  56. //When player is hit by the rock teleport them back to the start
  57.  
  58. OtherActor->SetActorLocation(PlayerStartingLocation);
  59. }
Add Comment
Please, Sign In to add comment