

I talked with Pavel_S about this bug on his helicopter mod and we agree there seems to be a bug in set_attach or set_detach in terms of rotation.
When the player is attached to an object (like helicopter or ostrich) AND the rotation (x or z) is set. Then when set_detach() is called the player exits the object and their rotation axis is broken. Does the l_set_detach function need a rotation variable to unset the rotation?
I've tried set_bone_position function before and after after set_detach but it didn't help.
src/script/lua_api/l_object.cpp around line 430
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
// set_attach(self, parent, bone, position, rotation)
int ObjectRef::l_set_attach(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
ObjectRef *parent_ref = checkobject(L, 2);
ServerActiveObject *co = getobject(ref);
ServerActiveObject *parent = getobject(parent_ref);
if(co == NULL) return 0;
if(parent == NULL) return 0;
// Do it
std::string bone = "";
if(!lua_isnil(L, 3))
bone = lua_tostring(L, 3);
v3f position = v3f(0, 0, 0);
if(!lua_isnil(L, 4))
position = read_v3f(L, 4);
v3f rotation = v3f(0, 0, 0);
if(!lua_isnil(L, 5))
rotation = read_v3f(L, 5);
co->setAttachment(parent->getId(), bone, position, rotation);
return 0;
}
// set_detach(self)
int ObjectRef::l_set_detach(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
ServerActiveObject *co = getobject(ref);
if(co == NULL) return 0;
// TODO: add optional bone, position, rotation as per set_attach code above?
// Do it
co->setAttachment(0, "", v3f(0,0,0), v3f(0,0,0));
return 0;
}
mods/helicopter/init.lua around line 80
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
function heli:on_rightclick(clicker)
if not clicker or not clicker:is_player() then
return
end
if self.driver and clicker == self.driver then
self.driver = nil
clicker:set_detach()
self.model:set_animation({x=0,y=1},0, 0)
elseif not self.driver then
self.model:set_animation({x=0,y=10},10, 0)
self.driver = clicker
clicker:set_attach(self.model, "Root", {x=0,y=0,z=-10}, {x=-90,y=0,z=-90})
end
end
Bug is in the rotation {x=-90,y=0,z=-90}.
https://forum.minetest.net/viewtopic.php?id=6183&p=3