Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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"

 class NOK_API ABarrier : public AActor
 // Sets default values for this actor's properties

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

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

     class UStaticMeshComponent* Mesh;
     class USceneComponent* Root;

     class UBoxComponent* ColliderMesh;

     FRotator tr;

     int flag;

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

     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
  // 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()

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

     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. :)

Product Version: UE 4.18
more ▼

asked Dec 02 '17 at 12:03 PM in C++ Programming

avatar image

1 2 3

avatar image virtual_nomak Dec 03 '17 at 12:28 AM

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?

avatar image mech_aadi Dec 03 '17 at 08:15 PM

Hmm..will let you know tomorrow if it works.

avatar image mech_aadi Dec 04 '17 at 02:47 PM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question