When I compile, I get an error, and it seems to take issue with my + operand.
I can’t figure out what is different in comparison to the video, I’m aware my top level naming is a bit different but it’s consistent across the class and it’s not what the code is complaining about.
Any ideas?
My code:
// Fill out your copyright notice in the Description page of Project Settings.
#include "MovingPlatform1.h"
// Sets default values
AMovingPlatform1::AMovingPlatform1()
{
// 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;
}
// Called when the game starts or when spawned
void AMovingPlatform1::BeginPlay()
{
Super::BeginPlay();
StartLocation = GetActorLocation();
}
// Called every frame
void AMovingPlatform1::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
MovePlatform(DeltaTime);
RotatingPlatform(DeltaTime);
}
void AMovingPlatform1::MovePlatform(float DeltaTime)
{
if (ShouldPlatformReturn())
{
FVector MoveDirection = PlatformVelocity.GetSafeNormal();
StartLocation = StartLocation + MoveDirection * MoveDistance;
SetActorLocation(StartLocation);
PlatformVelocity = -PlatformVelocity;
}
else
{
FVector CurrentLocation = GetActorLocation();
CurrentLocation = CurrentLocation + (PlatformVelocity * DeltaTime);
SetActorLocation(CurrentLocation);
}
}
void AMovingPlatform1::RotatingPlatform(float DeltaTime)
{
FRotator CurrentRotation = GetActorRotation();
CurrentRotation = CurrentRotation + PlatformVelocity * DeltaTime;
SetActorRotation(CurrentRotation);
}
bool AMovingPlatform1::ShouldPlatformReturn() const
{
return GetDistanceMoved() > MoveDistance;
}
float AMovingPlatform1::GetDistanceMoved() const
{
return FVector::Dist(StartLocation, GetActorLocation());
}
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "MovingPlatform1.generated.h"
UCLASS()
class OBSTACLEASSAULT_API AMovingPlatform1 : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AMovingPlatform1();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
private:
UPROPERTY(EditAnywhere, Category="Moving")
FVector PlatformVelocity = FVector(100, 0, 0);
UPROPERTY(EditAnywhere, Category="Moving")
float MoveDistance = 100;
UPROPERTY(EditAnywhere, Category="Rotation")
float RotationVelocity;
FVector StartLocation;
void MovePlatform(float DeltaTime);
void RotatingPlatform(float DeltaTime);
bool ShouldPlatformReturn() const;
float GetDistanceMoved() const;
};
Error:
O:\Development\GameDevCourse\Obstacle\ObstacleAssault\Source\ObstacleAssault\MovingPlatform1.cpp(57): error C2678: binary '+': no operator found which takes a left-hand operand of type 'FRotator' (or there is no acceptable conversion)
O:\Development\GameDevCourse\UE_5.0\Engine\Source\Runtime\Core\Public\Math\Rotator.h(119): note: could be 'UE::Math::TRotator<double> UE::Math::TRotator<double>::operator +(const UE::Math::TRotator<double> &) const'
O:\Development\GameDevCourse\UE_5.0\Engine\Source\Runtime\Core\Public\Misc\FrameTime.h(204): note: or 'FFrameTime operator +(FFrameTime,FFrameTime)'
O:\Development\GameDevCourse\UE_5.0\Engine\Source\Runtime\Core\Public\ProfilingDebugging\ResourceSize.h(115): note: or 'FResourceSizeEx operator +(FResourceSizeEx,const FResourceSizeEx &)'
O:\Development\GameDevCourse\Obstacle\ObstacleAssault\Source\ObstacleAssault\MovingPlatform1.cpp(57): note: while trying to match the argument list '(FRotator, UE::Math::TVector<double>)'
Build failed.```