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 "UnrealTutorial.h"
- #include "MyActor.h"
- // Sets default values
- AMyActor::AMyActor()
- {
- // 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;
- tBox = CreateDefaultSubobject<UBoxComponent>(TEXT("Root"));
- tBox->bGenerateOverlapEvents = true;
- tBox->OnComponentBeginOverlap.AddDynamic(this, &AMyActor::TriggerEnter);
- tBox->SetRelativeScale3D(BoxSize);
- RootComponent = tBox;
- MyMesh = CreateAbstractDefaultSubobject<UStaticMeshComponent>(TEXT("MyMesh"));
- MyMesh->AttachTo(RootComponent);
- SpeedScale = 0.0f;
- }
- // Called when the game starts or when spawned
- void AMyActor::BeginPlay()
- {
- Super::BeginPlay();
- }
- // Called every frame
- void AMyActor::Tick( float DeltaTime )
- {
- Super::Tick( DeltaTime );
- FVector NewLocation = GetActorLocation();
- float DeltaHeight = (FMath::Sin(RunningTime + DeltaTime) - FMath::Sin(RunningTime)); //bounces the object between 0 and -1
- //when the obj goes to 0 it starts to move down. when the obj goes to -1 it starts to move up
- NewLocation.X += DeltaHeight *SpeedScale;
- RunningTime += DeltaTime;
- SetActorLocation(NewLocation);
- }
- void AMyActor::TriggerEnter(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
- {
- //When player is hit by the rock teleport them back to the start
- OtherActor->SetActorLocation(PlayerStartingLocation);
- }
Add Comment
Please, Sign In to add comment