Hello,
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:
- Refresh Code
- Delete various deletable files and rebuilt my file.
- Checked it against Roll. I found that regardless of what roll was at, once past a certain number it would twitch.
- 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
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
URollPitchYaw();
protected:
// Called when the game starts
virtual void BeginPlay() override;
public:
// 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
private:
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;
UPROPERTY(EditAnywhere)
ATriggerVolume* PitchTrigger = nullptr; // Set Trigger
UPROPERTY(EditAnywhere)
float OpenPitch = 90.f;// set Pitch Rotation
UPROPERTY(EditAnywhere)
float PitchSpeed = 2.f; //Pitch Rotation speed
UPROPERTY(EditAnywhere)
bool bPitchExactWeight = false;//Set if want exact weight
UPROPERTY(EditAnywhere)
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
URollPitchYaw::URollPitchYaw()
{
PrimaryComponentTick.bCanEverTick = true;
}
void URollPitchYaw::BeginPlay()
{
Super::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.
PitchAnimation(DeltaTime);
}
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;
GetOwner()->SetActorRotation(PitchRotation);
UE_LOG(LogTemp, Error, TEXT("%f is the Pitch"), PitchRotation.Pitch)
return;
//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.