Problem Rotating child Actor

Hi, for this exercise i do the following:

As you can see i attached the door to the frame as child, but got a weird rotation when the trigger is not active like this

void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
if (DoorTriggerVolume->IsOverlappingActor(OverlapingActor))
{
//GLog->Log(“Encontro a el actor Sobre el volumen”);
bOpenDoor = true;
}
else
{
bOpenDoor = false;
}
OpenDoor(DeltaTime);
}

void UOpenDoor::OpenDoor(float DeltaTime)
{
FRotator rotation = GetOwner()->GetActorRotation();

if (bOpenDoor==true)
{
if (rotation.Yaw < OpeningAngle)
{
//GLog->Log(“Abriendo Puerta”);
GetOwner()->SetActorRotation(rotation + FRotator(0.f,DeltaTime * OpeningVelocity,0.f));
}

}
else
{
if (rotation.Yaw > 0.f && bOpenDoor == false)
{
//GLog->Log(“Cerrando Puerta”);
GetOwner()->SetActorRotation(rotation - FRotator(0.f, DeltaTime * OpeningVelocity, 0.f));
}
}
}

This are the Values on the transform for the door and the frames:

Frame:

image

Door:

image

On mi BeginPlay function i do the following to get the initial yaw:

void UOpenDoor::BeginPlay()
{
Super::BeginPlay();

// …
bOpenDoor = false;
FRotator rotation = GetOwner()->GetActorRotation();
GLog->Log("OWNER: " + GetNameSafe(GetOwner()));
GLog->Log("YAW: " + rotation.ToString());

}

But when i get the output log i get this:

LogTemp: Repeating last play command: Selected Viewport
OWNER: SM_Door_9
YAW: P=0.000000 Y=89.999992 R=0.000000

image

So, i try to get a method to get the local rotation but don’t find any, there’s any error with my thinking or there’s an error on unreal api?

So, for any one that fount this intresting, i found the solution:

//Get the Parent Actor

AActor *parent = GetOwner()->GetAttachParentActor();

//Check if not null
if (parent!=nullptr)
{
GLog->Log("parent -> " + parent->GetName());

// get the rotation relative to parent
FRotator relative = GetOwner()->GetTransform().GetRelativeTransform(parent->GetTransform()).Rotator();
GLog->Log("Relative -> " + relative.ToString());
}
​​

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

Privacy & Terms