Need help for variation to door opening

Hello, I am trying to apply the knowledge learned in this session implementing a variation on door opening.
A big wood door should open when the player rotates a skull.
I was able to rotate the skull when hit by the player and the right button is pushed.
I was also able to open the big wood door when the function OpenWoodDoor() in OpenWoodDoor.cpp component attached to the door actor is called.
I have now to call the function OpenWoodDoor() from Grabber.cpp when the skull rotates but I don’t know how to do that. Or as alternative to set a global bool variable in OpenWoodDoor.cpp from Grabber.cpp.
May be a better knowledge of OOP, that I don’t have, from my side could help.
Hope the question is clear. Thank you for any help.

You should be able to do essentially the same thing that was done in the videos though it won’t be a great design as you would have to do FindComponent which I think is a bit error prone.

To make it a bit easier I would suggest you create a class derived from Actor and call it something like InteractableMesh. Under a private section in the header

private:
    UPROPERTY()
    USceneComponent* DummyRoot;
    UPROPERTY()
    UStaticMeshComponent* Mesh;

And create an instance of that in the constructor.

UInteractableMesh::UInteractableMesh()
{
    DummyRoot = CreateDefaultSubobject<USceneComponent>(TEXT("DummyRoot"));
    Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));

    RootComponent = DummyRoot;
    Mesh->SetupAttachmeent(DummyRoot);
}

The bulk of that is explained in Toon Tanks. The part that isn’t is the dummy root. It’s used a reference point so that you can use relative rotations.
So if you put an instance of this actor into your scene the DummyRoot’s location/rotation is fixed and the relative rotations on Mesh would be relative to that component’s. i.e.

Mesh-SetRelativeRotation(FRotator(0.f,90.f,0.f));

Would be + 90 yaw regardless to the absolute rotation.


Then your rotate functions that you want to apply from the skull should be made public then hook it all up e.g. in wherever the code for your skull is

UPROPERTY(EditInstanceOnly)
InteractorableMesh* Interactable;

Hello Daniel,
thank you for the suggestion but I am not sure I have fully understood.
I did what you wrote, so now I have :

  1. The class AInteractableMesh with the static mesh of the skull and a public function RotateSkull() that rotates 90 degrees the mesh (skull). I dragged this class into the scene;
  2. The actor WoodDoor with the component OpenDoor and the function OpenDoor() that rotates the door;
  3. The class DefaultPawn_BP with the component Grabber and the function Grab(). Inside this function I detect if the skull is grabbed and in that case it is rotated 90 degrees. But I can rotate the skull because I get its reference since it is the hit object, I don’t have any reference of the WoodDoor, how can I call the function OpenDoor() ?

Thank you again for the help.
Stefano

I’ll try throw up an example for you later.

1 Like

So a little more involved than my comment suggested. As I didn’t know how you were doing the skull rotation interaction.

Here’s a rather basic example
https://github.com/SuperWig/Interactable

1 Like

WOOOOOWWWW !!! Daniel, thank you so much.
Your code is very clear and strightforward. There are very interesting aspects that I need to investigate, i.e. this code to cast the hit actor to AInteractableActor:
AInteractableActor* Interactable = Cast(Hit.GetActor());
I didn’t get there that I could use it.

In the end I even got a solution by myself in this way:

  • I did the class AInteractableMesh with the static mesh of the skull as per your indications and the function GetSkullRotation();
  • When the skull is grabbed it is also rotated:
    HitResult.GetComponent()->SetRelativeRotation(NewRotation);
  • Inside UOpenWoodDoor::TickComponent I check if the skull is rotated and in that case I open the door :
    FRotator SkullRot;
    SkullRot = Mesh->GetSkullRotation();
    if (SkullRot.Yaw > 75.0f)
    {
    OpenWoodDoor(DeltaTime);
    }

Thank you a lot again for your help.

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

Privacy & Terms