When laying down in a bed while moving the movement doesn't stop.
We probably need set_velocity for players to fix this.
I'm fairly familiar with this bug. I already prevented it by checking the moving keys during the right-click : https://github.com/minetest/minetest/blob/master/doc/lua_api.txt#L2548-L2549
@kilbith checking the actual velocity of the player is even better, since you can move without pressing keys. But what should we do if the player is moving while rightclicking bed? Should we just ignore the click? That would be rather unresponsive and the player might get the impression that the bed is not working.
Btw you need get_player_velocity for patching.
Another option could be set_physics_override with speed set to 0.
@kahrl thats what we currently do. The problem is that the current velocity of the player is preserved.
@PilzAdam Arguably that is an engine bug then... One would assume that with speed set to 0, the player would stop moving.
@kahrl I wouldn't consider it a bug. The speed parameter sets how fast the player can move by holding the movement keys. It does not limit the velocity caused by other factors (e.g. falling or being pushed by things).
I've encountered that problem with some nodes in my cottages mod as well. It is problematic as the player may drift further away and get out of reach of the node he is sitting/sleeping on, thus making getting up tricky (the nodes there do not serve to skip the night but to set the player animation, so there's no auto-getup after a time).
set_player_velocity on the engine's side would be highly welcome. It could also be used for elevators, escalators, rails and the like.
Checking the player's speed and refusing usage of the piece of furniture in case of too high speed does not always work sufficiently reliably.
I'd think that there would be nothing wrong with setting the player speed identical to the entity speed when it is attached. This can be done in builtin or in core?
This is still happening :/
In MCL2, I fixed this in a fashion like kilbith suggested.
Check if the player velocity is smaller than a very small number. Only then the player is allowed to sleep. If the player moves, the player cannot go to bed and there will be a message in chat. Not ideal, but better than sleepwalking, and this is a perfectly reasonable workaround as long set_player_velocity does not exist.
Thanks that sounds good.
This should be closed now?