Is there any way to mount objects with an offset in world coordinates?
by Johannes Pauw · in Torque Game Builder · 02/03/2012 (11:17 am) · 5 replies
It doesn't look like there's a way to do this, but I figured I'd throw it out there since it would simplify something I'm trying to do by a hell of a lot.
Does anyone know if there's a way to have your mount offset be in world coordinates and stay that way? Like, I want one object to mount to another at a 0.1 offset y in world coordinates, and stay at that offset, while using the rotation from the object it's mounted to. Right now I'm just mounting to an invisible sceneobject and setting the rotation manually, but I'd really prefer to have this automated if possible.
Does anyone know if there's a way to have your mount offset be in world coordinates and stay that way? Like, I want one object to mount to another at a 0.1 offset y in world coordinates, and stay at that offset, while using the rotation from the object it's mounted to. Right now I'm just mounting to an invisible sceneobject and setting the rotation manually, but I'd really prefer to have this automated if possible.
About the author
Recent Threads
#2
t2dSceneObject has a set of "other methods" which includes getLocalPoint() and getWorldPoint() which are probably what you need.
This next part is absolutely untested, but here is an attempt at some code:
02/03/2012 (5:59 pm)
mount() has parameters of offsetX and offsetY. So I'm assuming your question is how to do it in world coordinates?t2dSceneObject has a set of "other methods" which includes getLocalPoint() and getWorldPoint() which are probably what you need.
This next part is absolutely untested, but here is an attempt at some code:
%worldOffset = "0 0.1";
%worldMountPoint = %this.getWorldPoint("0 0"); // center of %this in world coords
%worldMountPoint = t2dVectorAdd(%worldPoint, %worldOffset); // add offset to world coords
%localPoint = %this.getLocalPoint(%worldPoint); // convert back to local coords
%shadow.mount(%this, %localPoint.x, %localPoint.y, ...);
#3
02/04/2012 (4:22 pm)
Unfortunately what I'm asking for is for the mount to stay in world coordinates -- so that when the object that was mounted to rotates, the object that is mounted does not move its position, only its rotation.
#4
02/04/2012 (5:13 pm)
Mounting is really to keep an object relative to its parent. If you only want the object to rotate with its parent, it would be much easier to write a function on a schedule to get the "parent" rotation and set the object to the same.
#5
That should do what you want. If you have multiple objects that you need to offset like this then store them all in a simset and step through each of them in the onUpdateScene.
02/05/2012 (11:09 pm)
function t2dSceneGraph::onUpdateScene(%this) {
targetObject.setRotation(sourceObject.getRotation());
targetObject.setPositionX(sourceObject.getPositionX() + targetObject.xOffset);
targetObject.setPositionY(sourceObject.getPositionY() + targetObject.yOffset);
}That should do what you want. If you have multiple objects that you need to offset like this then store them all in a simset and step through each of them in the onUpdateScene.
Torque Owner Nic Biondi
Default Studio Name