Game Development Community

Quick mount question SOLVED

by David Horn · in Torque X 2D · 08/15/2009 (3:08 pm) · 11 replies

How do you get the world position of a mounted object?


T2DShape3D head = (T2DShape3D)TorqueObjectDatabase.Instance.FindObject("phead");
bool huh = pmodel.MountShape(head, "Bip01 L Finger1");
float mountx = pmodel.GetMountedObject("phead").Position.X;

pmodel is mty character - a T2DShape3D

The shape is mounted correctly, but mountx turns out to be null.




#1
08/16/2009 (2:13 pm)
Hey David,

I'm guessing you meant to state that pMode.GetMountedObject(...) it returning null because mountx can't be null, its a value type :)

Assuming the above, I believe the mount works by operating on the object you wish to mount. I'm not too familiar with the MountShape(...) function, but if it works anything like the Mount(...) function on the T2DSceneObject then I believe you just need to do the reverse:

head.MountShape(pmodel, "Bip01 L Finger1");

This is stating that you wish to mount the head onto the pmodel.
#2
08/16/2009 (4:15 pm)
Hey Lucas,

Thanks so much for the response.

Really what I'm trying to do is somehow determine the world position of my character's head as opposed to his feet. My thought was to mount something to the head and feet and then track that mounted object's position. All I can get right now is the position of the character himself (which is really the stationary bounds box in the dts file).

Actually the way I have it now works fine. It mounts perfectly to my character. The problem is that I can't access the object's position. As I was looking at the source code, once the mounted object get mounted, it is unregistered from the Torquedatabase. So torque doesn't know what position the mounted object is.
#3
08/16/2009 (6:29 pm)
Quote:As I was looking at the source code, once the mounted object get mounted, it is unregistered from the Torquedatabase.

Ah yes, I just saw this in the source too. I guess the MountShape(...) function isn't the same as the Mount(...) function then :). It doesn't looks like you'll be able to track this mounted object since it gets Unregistered.

Quote:ally what I'm trying to do is somehow determine the world position of my character's head as opposed to his feet.

Can you clarify or maybe give an example? I'm not quite sure what you are asking.

Do you mean you want to get the world position of the character's head relative to his feet? i.e., feet is the origin?
#4
08/16/2009 (7:15 pm)
Absolutely

Here's 2 examples.

1. In my game, there are various grapple moves. Let's say I do a bodyslam on my opponent. Within 3D Max, I create the animation of the character getting thrown with the bounds box remaining still. That way I have perfect control over all X/Y movement. The problem is that Torque only identifies the T2DShape3D's position with the bounding box. So it thinks it's standing perfectly still. So after the animation is over, even though the character appears to have been thrown, he snaps right back where he started. In my old TGE game, I fixed this by looking at where a node/mesh/bone/whatever's position was and then changed the character's position to his upon animation complete. That way I had animation-based movement.

The grapple motions are just too specific to control the movement at various times with physics components. I just need to find out where the character ends up when he's finished with the animation and then set his Position to that coordinate.

2. Also, when he's lying down, I want to have different moves if a character near the downed opponent's head or feet.

So anyway, since I can't seem to get the world position of a node, mesh or bone within my T2DShape3D, my idea was to mount things to the head, feed and center of my character (which I can do) and then track the positions of those mounted objects (which I can't do).

Hope that makes sense.
#5
08/16/2009 (8:36 pm)
Quote:So anyway, since I can't seem to get the world position of a node, mesh or bone within my T2DShape3D, my idea was to mount things to the head, feed and center of my character (which I can do) and then track the positions of those mounted objects (which I can't do).

Have you tried using a link point for this instead of mounting an object?

I wish I knew enough about the T2DShape3D's implementation to offer a better solution, but unfortunatly I don't.
#6
08/16/2009 (9:16 pm)
I don't think link points know where a mesh or bone is.
#7
08/16/2009 (9:45 pm)
Quote:I don't think link points know where a mesh or bone is.

Hmm yeah, I suppose it wouldn't have any information about the mesh itself.

Looking at the code a bit more it looks like you can use the NodeTransforms property on the ShapeInstance class to obtain the transform matrix required to find the world space coordinates for each node.

It looks like you'll need to change the access from protected to public to access them; I don't see another way to access them publically. Have you tried to using this property?
#8
08/17/2009 (10:09 am)
No, I havent.

I'll have to look back and see how you modify the source code. Originally, I just used the StarterGame2D template. But after reading someother posts, I think I have to copy the torque source folders next to my project and change the reference to them (as I believe you suggested in my other post.)

Then, maybe I can just change the code there and simply save the files to get the game to regognize the change. Maybe then I can change that property to public - or even try to write a function that helps.
#9
08/18/2009 (9:01 pm)
Ok, I'm almost there

I can in fact get the NodeTransforms, however it looks like it's a Matrix.

Is there any way that I can convert that into a world x and y position?
#10
08/18/2009 (9:58 pm)
Quote:Ok, I'm almost there

I can in fact get the NodeTransforms, however it looks like it's a Matrix.

Is there any way that I can convert that into a world x and y position?

Ok, this is the part where I think you'll have to do some trial an error :)

I'm not sure what space these nodes are in when they are loaded (in fact I don't even know what nodes are). But my guess is that they are in object space. Assuming this is true, you'll need to convert the object space to world space to get your coordinates.

Now there is one more problem I see here, unless your overridding the Render(...) method somewhere, I don't see an easy way to obtain the SceneRenderState which holds the current World matrix you need. So first I think you need to change the protected SceneRenderState to public so you can grab it from the T2DSceneGraph you are currently using. After that you should just need to Multiply the NodeTransform matrix by the SceneRenderState.World matrix. After this I believe you can use the Matrix.Translation property to obtain the translation vector of the node.

Again, this might not be correct. But let me know what you come up with and we can work it out from there.
#11
08/21/2009 (10:17 am)
That did it.

You're the man Lucas!