Rotating an actor at a specific angle

Hey, I want a help, I am making a project and i want to rotate an actor(A barrier) to 90 degrees when it enters a box trigger and when the condition is true, checking it in tick function and then stop to that same angle(90 degrees) i can rotate the actor with FRotator in the tick() function but i can’t make it stop to that angle(90 degrees)
its just keep rotating.

Help me in this.

Of course, using C++

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Barrier.generated.h"

UCLASS()
class NOK_API ABarrier : public AActor
{
GENERATED_BODY()

public:	
// Sets default values for this actor's properties
ABarrier();

protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;

 public:	
// Called every frame
virtual void Tick(float DeltaTime) override;

UPROPERTY(EditAnywhere)
	class UStaticMeshComponent* Mesh;

UPROPERTY(EditAnywhere)
	class USceneComponent* Root;

UPROPERTY(EditAnywhere)
	class UBoxComponent* ColliderMesh;

UPROPERTY(EditAnywhere)
	FRotator tr;

UPROPERTY(EditAnywhere)
	int flag;


UFUNCTION()
	void OnPlayerEnter(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* Othercomp, int32 otherbodyIndex, bool bFromSweep, const FHitResult& Sweep);

UFUNCTION()
	void OnPlayerExit(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* Othercomp, int32 otherbodyIndex);

};

// Fill out your copyright notice in the Description page of Project Settings.

#include "Barrier.h"
#include "Components/StaticMeshComponent.h"
#include "Components/SceneComponent.h"
#include "Components/BoxComponent.h"

// Sets default values
ABarrier::ABarrier()
{
// 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;
Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
Root = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
ColliderMesh = CreateDefaultSubobject<UBoxComponent>(TEXT("Collider"));

Mesh->AttachToComponent(Root, FAttachmentTransformRules::SnapToTargetNotIncludingScale);
ColliderMesh->AttachToComponent(Root, FAttachmentTransformRules::SnapToTargetNotIncludingScale);

RootComponent = Root;

flag = 0;

ColliderMesh->bGenerateOverlapEvents = true;

ColliderMesh->OnComponentBeginOverlap.AddDynamic(this, &ABarrier::OnPlayerEnter);
ColliderMesh->OnComponentEndOverlap.AddDynamic(this, &ABarrier::OnPlayerExit);

}

// Called when the game starts or when spawned
void ABarrier::BeginPlay()
{
Super::BeginPlay();

}

// Called every frame
void ABarrier::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if (flag == 1)
{
	FRotator tr = GetActorRotation();
	tr.Roll += 10.0f;
	SetActorRelativeRotation(tr);

	if (tr.Roll==40.0f) {
		tr.Roll = 0.0f;
	
	}
}

}

void ABarrier::OnPlayerEnter(UPrimitiveComponent * OverlappedComp, AActor * OtherActor, UPrimitiveComponent * Othercomp, int32 otherbodyIndex, bool bFromSweep, const FHitResult & Sweep)
{
flag = 1;
}

void ABarrier::OnPlayerExit(UPrimitiveComponent * OverlappedComp, AActor * OtherActor, UPrimitiveComponent * Othercomp, int32 otherbodyIndex)
{
}

Thanks. :slight_smile:

You should start using DeltaSeconds in there, I believe your issue may be that you are checking if the rotation is exactly 40.0f and if you are not using DeltaSeconds the update of this value may occur during a black frame thus not updating back to 0.0f. Why don’t you try logging those values on the Output log and see what comes out?

Hmm…will let you know tomorrow if it works.

Hey… got it working but the barrier is flickering i want it freeze… can u help me with that?