Page 1 of 1

set_attach and set_detach rotation. [solved]

Posted: Wed Mar 19, 2014 02:15
by dmonty
Image

Image

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

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

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}.

viewtopic.php?id=6183&p=3

Posted: Wed Mar 19, 2014 02:29
by dmonty
When I attach a clicker to an object with no rotation - the player detaches with no rotation bug. However the player does not sit correctly in the object.

e.g. rotation {x=0,y=0,z=0}

Code: Select all

clicker:set_attach(self.model, "Root", {x=0,y=0,z=-10}, {x=0,y=0,z=0})

Posted: Fri Mar 28, 2014 13:47
by dmonty
Fixed this one by not attaching to the Root of the mesh.

viewtopic.php?pid=135079#p135079