Game Development Community

SetTransform doesn't update object correctly

by Darius · in Torque Game Engine · 10/25/2008 (11:08 am) · 4 replies

I have a StaticObject that I am trying to move around using the setTransform method. What's strange is that I call setTransform, and the object's bounding box moves, but the object continues to be rendered in the old position. If I'm in the mission editor, and I click on the bounding box and move the object, then the object will start rendering in the new position. The strangest thing is that sometimes, for no reason apparent to me, the object will start rendering correctly. I push the movement keys, and the bounding box moves, then after a slight delay the object starts rendering in the correct position.

I thought my problem might be similar to this issue: http://www.garagegames.com/mg/forums/result.thread.php?qt=18040 But I'm using a StaticShape instead of a TSStaticShape, and I checked my C++ code to make sure that the Position bit was being set after the transform was set.

Here's the method where I do the transform:

function PlayerTokenData::moveToken(%db,%obj,%newPosition) {
%obj.setTransform(%newPosition SPC "1 0 0 0");
%obj.setScale("1 1 1");
}

There's not a lot to it, and I'm not really sure what I might be doing wrong. I've been messing with it for a couple of hours now and I'm hoping someone can help point me in the right direction. Thanks.

#1
10/25/2008 (11:28 am)
I'm no expert on this, but it seems you are missing a function call.

You need something like:
{psuedo code not tested}
%oldPosition.%obj.getTransform();
       %newPosition = getWord(%trans, 3)
          SPC getWord(%trans, 4)
          SPC getWord(%trans, 5)
          SPC getWord(%trans, 6);
%obj.setTransform(%newPosition SPC "1 0 0 0");
%obj.setScale("1 1 1");
Or something to that effect. You need to get the old position and update it to the new position.
#2
10/25/2008 (11:38 am)
Thanks for the reply, I am actually doing that elsewhere, here's the code that does that:

function shiftPlayerToken(%dx,%dy,%dz) {
	%transform = InfiltrationPlayerToken.getTransform();
	%position = getWords(%transform, 0, 2);
	%infilDB = InfiltrationPlayerToken.getDatablock();
	%newPosition = vectorAdd(%position, %dx SPC %dy SPC %dz);
	%infilId = InfiltrationPlayerToken.getId();
	%infilDB.moveToken(%infilId,%newPosition);
}
You can see I call the method I posted earlier at the bottom of the shiftPlayerToken method. This method gets called by a server method, with the difference in x, y and z. I have the two methods separated because I was planning on making the moveToken method a little more full featured once I got the base stuff working.
#3
10/27/2008 (8:31 pm)
So I've played around with it some more, and I've narrowed it down some, I'm still baffled as to what is wrong, but maybe this added information will help someone help me.

I'm creating the StaticShape that I'm trying to move in script, I'm also creating about a hundred other static shapes in script. Here's the code where I create the object I'm trying to move around:

$PlayerTokenVar = new StaticShape(InfiltrationPlayerToken) {
		datablock = "InfiltrationPlayerTokenDataBlock";
	};

and here's the code where I'm creating the other objects:
for(%x = 0; %x < %networkSize; %x++) {
		for(%y = 0; %y < %networkSize; %y++) {
			%checkVal = getRandom();
			if(%checkVal > %networkSparseness) {
				//create the new network node here
				$NodeArray[%x,%y] = new StaticShape() {
					datablock = "NetworkNodeDataBlock";
					position = (%x*10) SPC (%y*10) SPC "0";
					rotation = "1 0 0 0";
				};
				//$NodeArray[%x,%y].setCloaked(true);
			}
		}
	}

And finally here's the code for the NetworkNodeDataBlock:

datablock StaticShapeData(NetworkNodeDataBlock)
{
	category = "Infiltration";
	shapeFile = "~/data/shapes/infiltration/NetworkNode.dts";
	cloakTexture = "~/data/shapes/infiltration/Material.png";
};

So that problem I described earlier, where the player token shape doesn't get rendered in it's new position, that only happens when I use the datablock when I'm creating the network node objects. If I comment out the line that says "datablock = "NetworkNodeDataBlock";" then it works fine, but then none of the objects I create have their datablocks.

I hope it's clear what I'm seeing, and that someone has an idea of what I'm doing wrong. Thanks.
#4
10/27/2008 (8:55 pm)
Okay, I think I solved it, in case anyone else sees a similar problem. I was creating too many StaticShape objects. If I have less than about 170 StaticShapes created, then the setTransform works fine, but after that it doesn't update the objects. Weird. I'll have to do some more looking into this, and/or just make sure I never use more objects than that.

I'm still open to any suggestions or observations if anyone has any.

Thanks.