Quick question regarding some basic C++ in UE4. I currently have a working door, walk up and press E and it snaps open 90degrees, press E again and it snaps closed 90degrees. This also plays an open and closed door sound accordingly. The problem is currently I’m just using the function SetActorRotation to open and close the door. Could anyone point me into the right direction on a better way to handle this? Should I be using an animation on the door or should I be animating it in the code by using a lerp or something? If I should be animating through the code is their any suggestions on how to do this? (I am new to UE4, coming over from Unity C#).
Included some pseudo code below to show how my door is currently working.
Thanks,
Mark
pseudo code:
class MyGameCharacter
Interactable CurrentInteractable;
CheckForInteractables() // determines if interactable object is in range (via linetrace), if so add to CurrentInteractable, otherwise assign nullptr. Function is called inside Tick()
Interact() // called when the key E is pressed, if CurrentInteractable != nullptr, call CurrentInteractable->Interact()
class Intractable
function Interact();
class Door (inherits Interactable)
bool bOpened;
bool bLocked;
UAudioComponent* door_open;
UAudioComponent* door_close;
UAudioComponent* door_locked;
function Interact() {
if(!bLocked)
{
if(!bOpened)
{
// play open animition OR rotate actor yaw by 90degrees?
playsound door_open;
bOpened = true;
}
else
{
// play close animition OR rotate actor yaw by -90degrees?
playsound door_close;
bOpened = false;
}
}
else
{
play door_locked;
}
}