Download

Using FMath::Lerp function to open a door and encountering collision issue on the UStaticMesh

Hi Everyone,

I have set up a door to open using the FMath::Lerp function when the player interacts with the door. The “door” is comprised of two static mesh components (door frame and the actual door). The door opens, but the player is still encountering an issue with walking through the open doorway even though it appears there should be no collision in the way.

I believe the FMath::Lerp function is causing some type of framerate situation causing the appearance of no collision but in fact the engine is computing collisions the player is running into.

I have attached screenshots of the in engine collision issue and the code driving the opening of the door. Any help would be much appreciated.

Are you sure there is no collision on the door frame? It’s hard to tell without seeing the setup of course, but the simple collision for that door frame mesh is probably just a solid box (with no holes).

I took collision off the door frame. I had the same thought as you regarding a solid box collision around the door frame still blocking.

I am actually going to take the door frame model out of Unreal, build collision into the mesh, and then reimport back into unreal to see if I get the same issue.

I have heard it is better to build collision into the models outside of the engine in some situations.

I would try with FMath::RInterpConstantTo(); or FMath::RInterpTo(); , instead of Lerp. Lerp acts weird with angles because the limit of 180 -180.

Example of lineal opening:

FRotator Opendoor = FMath::RInterpConstantTo(ActualRotation, DesiredRotation, DeltaTime, Speed);
DoorStaticMesh->SetActorRotation(OpenDoor);

ActualRotation is a FRotator, you can get with GetActorRotation();
DesiredRotation is a FRotator you can get with GetActorRotation() + FRotator(0.f, 90.f, 0.f); save in a FRotator variable before rotate the door to have the original rotation (when is closed) + 90 degrees rotation
DeltaTime is just DeltaTime from Tick
Speed is a float which will determine how fast or slow is the animation.

FRotator Opendoor = FMath::RInterpTo(ActualRotation, DesiredRotation, DeltaTime, Speed);
DoorStaticMesh->SetActorRotation(OpenDoor);

this is the same but will do the animation smooth, instead lineal.

If you still have problems to pass, maybe the character capsule is too big? or try
DoorFrameStaticMesh->SetActorEnableCollision(false);
to disable the frame collision and check if it is the problem.

1 Like

Thank you so much for this insight @ikifenix . I was unaware those two FMath functions existed.

I will give them a try and let you guys know how everything works out.

FYI:

  • run game in Editor
  • open door
  • try to walk through
  • hit “Eject”
  • console ~ “show collision”

And you will see your player collision capsule and exactly what it is colliding with.

@Shmoopy1701 That is what I did, and from the screenshots it does not look like the player capsule should be colliding with anything. I think @ikifenix is on to something with using FMath::RInterpConstantTo() function versus just using FMath::Lerp().

When the player capsule “collides” it is almost like there is a framerate/tick calculation issue going on with the engine trying to determine where the actual door should be in the world.