Hello everyone, I need some help figuring out a problem in my door system.
My door system consist in a simple door mesh with simulated physics and basic constraints to make it rotate on the Z axis, the door closes itself when the player is at a certain distance from it.
The issue is that once I place my door in the level everything works just fine until i start to rotate the door past 180° to make, for instance, a double door. It looks like that when the origin of the mesh goes past 180° and switches to negatives numbers (-179° etc…) the door tries to close itself by making a full turn the wrong way.
I think the problem is that when the actor is rotated in the world the blue print is trying to correct its rotation by going from -0° etc.. back to positive numbers (or something like this), as you can see from the video it happens only when the door is open in one direction, wich is the direction that goes to negative numbers.
I know it’s a bit confusing but I really can’t find any solution to this by myself, any ideas?
Thank you in advance!
I’ll leave my code down here with a video for better undertanding
I don’t see a specific need for collision detection just to close, however you can still do that simply on collision enable angular drive to swing, will make door return original rest position.
In terms of doors, different type of interactions, contextual interactions, locks, destruction etc if you have needs let us know since doors can get sophisticated.
Would you use a hidron collider to compress oxigen into a tank?
Thats exactly what you are attempting to do by using physics to handle something that should have no place being handled by physics - just like they hydron collider has no place making and canning oxigen.
Depends on the need to be honest, if want it to be physics handled why not, some games have that. Howerver its true that handling a crucial gameplay mechanics just by physics is not a long term good idea.
What happens when an npc behind door.
What happens to doors when something explodes nearby.
Can door be only opened by pawn object.
What if door needs to be locked after you enter inside immidiately.
What if 2 npc try to get from door in such a moment of swing and get stuck.
Can go on and on..
@MostHost_LA is right about the complexity vs need, however I disagree with the " no place being handled by physics". Some games have different types of physics doors and physics simulated but limited, the thing is to be forward thinking about the need and the potential results for the future in a crucial gameplay element that will handle a lot of logic in future.
This should be simple with a sub-body for the door.
Use a soft angular constraint (hinge.) Lock all axes except rotation around the Z axis.
Contrary to other suggestions here, I think that’ll work great and be a simple and robust solution that works well with other things happening (e g, throwing boulder at the door)
I’d like the door to be opened by the player by using physics because it looks better (also for immersion purposes) and I want the doors to automatically close behind the player mostly because I want them to be locked in specific moments of the gameplay etc… By closing it via blueprint I’m making sure it is at his exact closed position, making it easier to give it specific functions (locking etc…)
I was inspired by the doors in resident evil 7/Village because they are kinda handled by physics when opened but close on their own when away from them. I think it look neat and works better during gameplay.
Don’t really like the saloon door style because the rotation Is not predictable at 100%
Also I don’t really like the bar door swing because It will swing back in the face of the player if they are still standing near the door range of motion, by going this way I’m making shure its always opened and moveable until i get out of the collision box that I use as a “safe zone” for the player to not get stuck in the door closing motion.
OnOverlap->Pawn->CloseDoorFunction->Lerp 0-1 Timeline → LerpRotator-> From CurrentRot to Zero (Default Start Pos) This will always choose the shortest path if you check the tick.
You can set door state to false from function which will,
SetDoorState(False)->Sim Physics Off → Close Function->If need closing-> CloseFunction
You can extend it more logic to make sure its closed, an event can occur when door is closed and locked so you will be sure that the function callback is valid.
Still there is a physics constraint applied to it since in level design you don’t want you door to hit objects etc. (or maybe you want)
This is the results for just closing it, that will never fail. (in terms of problem space you defined so far)
Notice physics is disabled when we interfere movement and status of the door, since in that moment of gameplay many things can happen to prevent door from closing. Like putting a heavy object in between, player drops some of the shields collected to there. As said you will define the need and keep in mind this is just a prototype raw and you will need events on door squences finished so that lerp events do not interfere the state.