Game Development Community

WeldJoint and setPosition() misbehaviour

by Amjad Yahya · in Torque 2D Beginner · 08/21/2013 (10:06 am) · 6 replies

I've created 2 objects, created weld joint using those 2 objects, then when I try to set the positionX to 0 it renders elsewhere.
%blueBird=createObject("blueBirdName", "blueBirdClass", "Dynamic", "115 23", "7.868 5.122", 8, "", "game:blueBirdAnimation");
	%shadow=createObject("", "", "Dynamic", "115 8.602", "11.719 1.640", 21, "game:shadow");
	myScene.createWeldJoint(%blueBird, %shadow, "0 -13.828", "0 0", 1, 0, false);
	%blueBird.setpositionX(0);

%blueBird.getpositionX() returns 0

#1
08/21/2013 (7:49 pm)
I've tested this just now and I can't reproduce the issue.

One thing that spring to mind is that, assuming your object(s) have collision shapes, if you set %bluebird's position to a location where it collides with another object, the physics will push the object or %bluebird out of the way a bit.
#2
08/22/2013 (1:15 am)
Now I get the right position.

It seems that I can't get it to behave the way I want it to, I weld two objects using
myScene.createWeldJoint(%obj1, %obj2, "0 -13", "0 0", 0, 0, false);
but when I change the position of the first object the second object does not follow it and stays in its original position. There are no other objects in the scene.

Let me rephrase my question: how can I mount two objects like we used to do in TGB without damping, freq., garavity (the good old fashioned mount), the second object would follow the first when I change its position and/or speed.
#3
08/22/2013 (2:28 pm)
You would have to use a CompositeSprite for a perfectly rigid connection between two objects. There is no mount functionality anymore like in TGB - it has been replaced with CompositeSprites and weld joints.
#4
08/23/2013 (2:59 am)
CompositeSprite won't work for me because:
1- I want to assign different layers to objects
2- I want to be able to call onAnimationEnd(), onTouchDown() for objects

Weld Joint almost worked for me except for the setPosition() issue, also moveTo() does not seem to be working properly with Weld Joints, the object never stops when reaching its target.

Still, I think the engine should have an old-fashioned-mount function, it's very useful especially for user interface functionality.
#5
08/23/2013 (4:47 am)
Well, you could always write a custom script/behavior that "connects" two objects in such a way that when you change the position of one object, the other follows.

Edit: posting from a phone is not really conductive for writing code, but I was thinking something like a setConnectedPosition method where you feed it coordinates and it calls setPosition for objects A and B. You could use a schedule too if you wanted a slight delay between each object moving.

There's also behavior connections, which has a small guide on the wiki. I haven't had the chance to use connections yet.
#6
08/23/2013 (10:39 am)
Thanks Mike.