Island Escape: Pitch is not working:


I had used the Open Door animation sequence and set it to Pitch instead (albeit in a less complicated manner). I found that in comparison to Yaw and Roll, Pitch would “twitch” and shake in a violent manner. But this would only happen at float 90+ both directions, getting worse the larger the number. This is despite the code seeming to be identical. As an interesting side result, if the character comes into contact with the jittery object, it will hit the character and send him flying. This has interesting possibilities, but not one that I want right now.

What I have done so far:

  1. Refresh Code
  2. Delete various deletable files and rebuilt my file.
  3. Checked it against Roll. I found that regardless of what roll was at, once past a certain number it would twitch.
  4. Made a Log to see what the Pitch’s rotation was sitting at as it twitched. It was stable, even if the graphic was not.

I have isolated the code below. I tried this out on its own with the results I had just mentioned.

// CopyRight MJJH 2021

#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "Engine/TriggerVolume.h"
#include "RollPitchYaw.generated.h"

UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class BUILDINGESCAPE_API URollPitchYaw : public UActorComponent

// Sets default values for this component's properties

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

	// Called every frame
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
        void PitchAnimation(float DeltaTime);//Starts the Pitch Rotation Animation
      float PitchTotalMassOfActors() const; // Calculate Total Mass of Actors on trigger


       float StartingPitch;// Pitch starting location
	float CurrentPitch;//Pitch current location

	UPROPERTY(EditAnywhere)//Turns this function on
		bool bPitchON = false;
	UPROPERTY(EditAnywhere)// Does not close door
		bool bPitchOnce;

		ATriggerVolume* PitchTrigger = nullptr;  // Set Trigger
		float OpenPitch = 90.f;// set Pitch Rotation
		float PitchSpeed = 2.f; //Pitch Rotation speed
		bool bPitchExactWeight = false;//Set if want exact weight

	float MassPressure = 50.f;//Set Mass Pressure
// CopyRight MJJH 2021

#include "RollPitchYaw.h"
#include "Components/AudioComponent.h"
#include "Components/PrimitiveComponent.h"
#include "Engine/World.h"
#include "GameFramework/PlayerController.h"
#include "GameFramework/ACtor.h"
#include "Math/UnrealMathUtility.h"
#include "Math/UnrealMathVectorCommon.h"

#define OUT

     PrimaryComponentTick.bCanEverTick = true;

void URollPitchYaw::BeginPlay()
//Sets up pitch location
	StartingPitch = GetOwner()->GetActorRotation().Pitch;
	CurrentPitch = StartingPitch;
	OpenPitch += StartingPitch;

void URollPitchYaw::TickComponent(float DeltaTime, ELevelTick TickType, 
FActorComponentTickFunction* ThisTickFunction)
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
// Calls up PitchAnimation function to change the actor's pitch.

float URollPitchYaw::PitchTotalMassOfActors() const
	//Calculates the TotalMassOfActors for Pitch to check against the Mass Pressure 
        float PTotalMass= 0.f;
	TArray<AActor*> POverlappingActors;

	if (!PitchTrigger){return PTotalMass;}

	PitchTrigger->GetOverlappingActors(OUT POverlappingActors);

	for (AActor* Actor: POverlappingActors)
		PTotalMass += Actor->FindComponentByClass<UPrimitiveComponent>()->GetMass();
	return PTotalMass;
void URollPitchYaw::PitchAnimation(float DeltaTime)
	if (!bPitchExactWeight)//if not exact weight then proceed....
		if (!bPitchON){return;}//If Pitch is not turned on, then do not continue	
		if (PitchTotalMassOfActors() >= MassPressure)// If the first is equal to or greater then, then proceed to rotate
//I Used OpenPitch variable for the Roll code, it the object rolled. When I used OpenRoll here, it did nothing.
			CurrentPitch = FMath::FInterpTo(CurrentPitch, OpenPitch, DeltaTime, PitchSpeed);
			FRotator PitchRotation = GetOwner()->GetActorRotation();
			PitchRotation.Pitch = CurrentPitch;

			UE_LOG(LogTemp, Error, TEXT("%f is the Pitch"), PitchRotation.Pitch)
//The Log above showed that the pitch number was stable, despite the twitch in the graphics that was happening. 

Here are some pictures as well:

Not at 90 rotation.

Certainly beyond 90. It was flipping and jittering from side to side.

I just copied that code and I’m not getting that behaviour.

If you can make an isolated test project I could look into it?

You can send me your project using the following link

Please use File > Package Project > Zip Up Project within Unreal as this will ensure only required files are zipped up and things like the Binaries are excluded.

I have just sent it.

I created an entirely new project and found the same problem. Note that I am using 4.26.2 if that makes a difference.

When I step on the trigger it starts, when I get off it stops. Go back on again, it starts again.

Hopefully it is not a bug in the version of Unreal that I have.

What you sent didn’t come with a map and the test map I made was exactly like the one in my previous one where I copied your code over (i.e. no bug).

No map? Did I somehow forget to save the map? I assume that the level is the same as the map? I used the default one that they gave me: Minimal_Default, and set my project to that.

By “no maps” I meant there’s no map that showcases the issue. The only maps are the ones that come with the starter content.

Btw if you want to minimise the file size to save on upload you should probably exclude the starter content.

Yes, that would be a good idea.


What version of Unreal are you using?


Mine is 4.26.2 if that matters.

Would you be able to package one up on your end and see if it works here?

Oh I’m an idiot, I forgot to change the pitch :sweat_smile:.

But that is an issue with the fact that GetActorRotation returns a value between -180 and 180. So it’s trying to reach a target that is impossible to reach.

You know, I should have just made it automatic and not on/off nor exact weight, since we wanted to confine it to the actual pitch rotation itself. So I set you up!

That is interesting. What would be the reason why it reacts at 90+ or -90+?

Presumably Current += OpenAngle goes outside of the range.

So perhaps try changing that to Current = Open Angle ?

Use relative rotations. Create a scene component and attach the mesh to that.

Now you no longer need to calculate the target as you can now just use relative rotations i.e. setting the relative rotation to +90 would be relative to the scene component which is in a fixed position.

That does mean you will now have to find the mesh from the owner to perform those relative rotations on.

I will see what I can do.

Should I do so with the others? Or is it mainly pitch?

It’s the rotation in general. As stated earlier GetActorRotation is going to return values between -180 and 180

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms