Community Forum

FS13: attaching objects

Forum Overview >> Scripting

CategoryScripting
Created16.03.2015 10:53


Bilbo Beutlin (BBeutlin) 16.03.2015 10:53
I want to attach an arbitrary object to a crane hook which is moveable up-down.

So far I use the method:

local constr = JointConstructor:new();
constr:setActors(self.rootNode, object);
constr:setJointTransforms(hookAttacherNode,object);
... etc. ...
attachedobject.JointIndex = constr:finalize();

So far it works. However the object is fixed, doesn't move with the crane hook. And "setActors()" only works with rootNode, otherwise crashes.
How can I make it moveable with the hook?

Emil Drefers (Unknown) 16.03.2015 14:36
Hi,

you have to update the joint.

setJointFrame(jointindex, anchorActor, joinitNode);

as used in
http://ls-mods.de/scriptDocumentation.php?lua_file=vehicles/specializations/ArticulatedAxis
for example.


Cheers,
Emil

Bilbo Beutlin (BBeutlin) 16.03.2015 15:49
Thanks, I got it :)

Besides: is there a way (joint method) without explicitely updating? so that the attached object moves 'automatically' with the attacherNode?

Emil Drefers (Unknown) 17.03.2015 09:55
Hi,

you would need to move not only the "attacherNode" but also the rigid body of which the attacherNode is a child.

As soon as the position of the attacherNode relativ to its "rigid body parent" changes you have to update the joint.

Cheers
Emil

Bilbo Beutlin (BBeutlin) 18.03.2015 01:46
I have still problems with my hook attacher.
Now the object follows the crane hook on movement. But when the hook stops, the object jumps back to initial position. What's missing?
Piece of code:

for i,att in pairs(self.attachedObjects) do
posX,posY,posZ = getTranslation(att.object);
setTranslation(att.object, posX + deltaX, posY + deltaY, posZ + deltaZ);
setTranslation(att.AT, posX + deltaX, posY + deltaY, posZ + deltaZ);
setJointFrame(att.JointIndex, att.object, att.AT);
end;


Note: Log in to post. Create a new account here.