Problems mounting StaticShapes to Player
by Fiona Counihan · in Technical Issues · 11/28/2006 (4:49 am) · 16 replies
Hi there,
I've been stuck for a while trying to implement mounting.
I have various different StaticShapes in my game and I want each of them to mount to my player object on Collision.
At the moment I am just calling the mountToPlayer() function with a key press to make sure that the objects are mounting correctly.
I have a Mount0 joint node in my Player DTS
I have mountPoint joint node in each of my Static shape DTS files.
When I run the mountToPlayer() function the Shape mounts to the player at Mount0 but not at mountPoint - it seems to be mounting at Origin.
When I mount these shapes to the player using Torque ShowTool Pro - (both Mount0 and mountPoint seem to have exported correctly because I can see them in the Show Tool) they mount correctly..
Does it look like I have gone about this the right way - or can anybody see something blatently wrong with what I'm doing??
function mountToPlayer()
{
echo(%player.getTransform());
echo(%obj1.isMounted());
echo(%player.getSlotTransform(0));
%player.mountObject(%obj1, 0);
echo(%player.getMountedObjectNode(0));
echo(%player.getMountedObject(0));
echo(%obj1.isMounted());
}
I've been stuck for a while trying to implement mounting.
I have various different StaticShapes in my game and I want each of them to mount to my player object on Collision.
At the moment I am just calling the mountToPlayer() function with a key press to make sure that the objects are mounting correctly.
I have a Mount0 joint node in my Player DTS
I have mountPoint joint node in each of my Static shape DTS files.
When I run the mountToPlayer() function the Shape mounts to the player at Mount0 but not at mountPoint - it seems to be mounting at Origin.
When I mount these shapes to the player using Torque ShowTool Pro - (both Mount0 and mountPoint seem to have exported correctly because I can see them in the Show Tool) they mount correctly..
Does it look like I have gone about this the right way - or can anybody see something blatently wrong with what I'm doing??
function mountToPlayer()
{
echo(%player.getTransform());
echo(%obj1.isMounted());
echo(%player.getSlotTransform(0));
%player.mountObject(%obj1, 0);
echo(%player.getMountedObjectNode(0));
echo(%player.getMountedObject(0));
echo(%obj1.isMounted());
}
About the author
#2
11/28/2006 (8:26 am)
I think you can only use mountpoint for a shapebaseimage. for object mounting, it just uses the origin. you may want to just export the object such that it's origin is at the desired mountpoint. either that, or just use an animation.
#3
Thanks for the links, they were very informative, at least I can stop rechecking my spelling of 'mountPoint' now, God I thought I was going mad!
I tried using mountEquipment() - but couldn't get it to work for some reason - did you get that to work?
-It compiles with no errors - Its just that when I use it in script:
%player.mountEquipment(%obj, "mount0"); ..nothin happens!
@Sean,thanks for the post,,
I took your advice and just exported the model with the Root node where I wanted mountPoint to be, so now it mounts where I wanted it to, however this won't do for what I want in the game..
What I actually need to do is onCollision with the player I need to change the position of the mountPoint or (Root node) so that the object mounts the player at the point of collision.
I was going to use Offset, but as far as I can tell this doesn't work with mountObjects, only mountImage?
I can't have my 'objects' as images because they need to be collidable and some of them need to have animations..
aagh, I foolishly though thtis was going to be simple?
Anymore help that anyone could give me would be greatly appreciated!
11/28/2006 (10:46 am)
@ Michael,Thanks for the links, they were very informative, at least I can stop rechecking my spelling of 'mountPoint' now, God I thought I was going mad!
I tried using mountEquipment() - but couldn't get it to work for some reason - did you get that to work?
-It compiles with no errors - Its just that when I use it in script:
%player.mountEquipment(%obj, "mount0"); ..nothin happens!
@Sean,thanks for the post,,
I took your advice and just exported the model with the Root node where I wanted mountPoint to be, so now it mounts where I wanted it to, however this won't do for what I want in the game..
What I actually need to do is onCollision with the player I need to change the position of the mountPoint or (Root node) so that the object mounts the player at the point of collision.
I was going to use Offset, but as far as I can tell this doesn't work with mountObjects, only mountImage?
I can't have my 'objects' as images because they need to be collidable and some of them need to have animations..
aagh, I foolishly though thtis was going to be simple?
Anymore help that anyone could give me would be greatly appreciated!
#4
11/28/2006 (11:30 am)
I think I have your solution, but I need to make sure I know what you are doing. Can you give an example of an object your player will be interacting with and how? Will he be bumping into a ball, which mounts to where the player collides with it?
#5
11/28/2006 (12:28 pm)
Sean H is incorrect. MountObject uses nodes also. They also have collision and animations, as do the images, sans collision, but images have states.
#6
11/28/2006 (1:09 pm)
@Allyn - However, staticShapes do not have collision or use proper mounting. They mount at the origin regardless of mountImage vs mountObject.
#7
Sequence of events:
1) staticshape on terrain. (of "Item class", i believe Item class has collision callbacks already)
2) Player bumps shape.
3) Remove shape from terrain. (or hide it)
4) Mount copy "Image" or "object" to player at node #.
Done.
I think terms are getting mixed up here.
11/28/2006 (2:17 pm)
Why would you mount a staticshape?Sequence of events:
1) staticshape on terrain. (of "Item class", i believe Item class has collision callbacks already)
2) Player bumps shape.
3) Remove shape from terrain. (or hide it)
4) Mount copy "Image" or "object" to player at node #.
Done.
I think terms are getting mixed up here.
#8
please feel free to correct me if I'm wrong about this.
11/28/2006 (2:52 pm)
Allyn what do you mean by "mountobject uses nodes also"? mountobject() uses nodes in that sense that you can choose a node to attach the staticshape to, but you can't specify a node on the staticshape to attach to the player. basically, instead of attaching an object to a node, Fiona is talking about attaching a specified node on one object, to a specified node on another object. from what I've seen, the only facility in torque which does this is shapebaseimage by specifying a "mountpoint" node on the model.please feel free to correct me if I'm wrong about this.
#9
thanks again for the help,
@Michael,
That is exactly what I wish to do , my player is not a 'human character' it is an instrument like a tweezers, I want the player to collide with a staticshape (ie a ball), then I play an animation called 'pinch' and I want the static shape to mount the player at the point at which the player collided with it. If you know a way that I could implement this I would be forever indebted!
@Allyn,
I know that mountObject is supposed to work in almost the same way as mountImage in that, taking the following example;
%shapeA.mountObject(%shapeB, 0)
ShapeA has a node called mount0, and shapeB has a node called mountPoint, calling the above code should cause shapeB to mount shapeA at mount0 and mountPoint, however it mounts at mount0 and Root (or so it seems to me!). I think this is what Sean is sayng too!
However I might use your method of removing the staticShape, adding an image of my shape and using the collision point transform to define some sort of offset, however this will be my last resort as I don't want to use images as my shapes still need to have collision, and in some case animation. ,
Cheers!
11/29/2006 (2:32 am)
Hi guys,thanks again for the help,
@Michael,
That is exactly what I wish to do , my player is not a 'human character' it is an instrument like a tweezers, I want the player to collide with a staticshape (ie a ball), then I play an animation called 'pinch' and I want the static shape to mount the player at the point at which the player collided with it. If you know a way that I could implement this I would be forever indebted!
@Allyn,
I know that mountObject is supposed to work in almost the same way as mountImage in that, taking the following example;
%shapeA.mountObject(%shapeB, 0)
ShapeA has a node called mount0, and shapeB has a node called mountPoint, calling the above code should cause shapeB to mount shapeA at mount0 and mountPoint, however it mounts at mount0 and Root (or so it seems to me!). I think this is what Sean is sayng too!
However I might use your method of removing the staticShape, adding an image of my shape and using the collision point transform to define some sort of offset, however this will be my last resort as I don't want to use images as my shapes still need to have collision, and in some case animation. ,
Cheers!
#10
I know in the Game Programmers's Guide to Torque; it states that the above calling should work. It explains the need for the proper Nodes[mount0 and mountPoint]. I see the verbatim quote from the book. If shapeB mounts on it's Origin and not the mountPoint; something is broken, because it's explained that it 'should' work.
There is too much time wasted trying to find out if something is broken or not....!
To fully resolve this, I feel script callings need to be exposed and a snapshot of your actual Node listing. This is going round and round.
Cheers.
11/29/2006 (6:33 pm)
It would be nice if a company representative stepped in and clarified if this is working in v1.5.I know in the Game Programmers's Guide to Torque; it states that the above calling should work. It explains the need for the proper Nodes[mount0 and mountPoint]. I see the verbatim quote from the book. If shapeB mounts on it's Origin and not the mountPoint; something is broken, because it's explained that it 'should' work.
There is too much time wasted trying to find out if something is broken or not....!
To fully resolve this, I feel script callings need to be exposed and a snapshot of your actual Node listing. This is going round and round.
Cheers.
#11
Box A in ShowTool - node: mount0

Box B in ShowTool - node: mountPoint

In-Game - Box B on top of Box A

my test...
box.cs
After the player spawns I create the boxes in the same position then mount b to a.
11/29/2006 (9:41 pm)
I deleted my post cause what I said was backwards but it does work as far as I can tell. Box A in ShowTool - node: mount0

Box B in ShowTool - node: mountPoint

In-Game - Box B on top of Box A

my test...
box.cs
datablock StaticShapeData( boxA )
{
shapeFile = "~/data/shapes/building/boxA.dts";
};
datablock StaticShapeData( boxB )
{
shapeFile = "~/data/shapes/building/boxB.dts";
};After the player spawns I create the boxes in the same position then mount b to a.
%this.spawnPlayer(%this);
%shapeA = new StaticShape() {
dataBlock = boxA;
position = "155 295 52";
};
%shapeB = new StaticShape() {
dataBlock = boxB;
position = "155 295 52";
};
%shapeA.mountObject(%shapeB, 0);
#12
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=10304
and I'm using that for the moment instead of mountObject, and I've used some (offset calculating) code posted before by Mike Cozzolino so at the moment it looks like:
BTW this is supposed to be (in the distant future) a surgical training tool fro a college project - in case you were wondereing about 'Liver' thing. My player is a surgical instrument like a tweezers!
However, At the moment when I collide with the Liver object a shapeBase Image of the Liver mounts to the player but not at the point of collision there is a big gap between the liver and the player,
This is the code that calculates the offset:
What is the offset parameter for ? is it to transform from the origin of the object (Liver) by the offset coordinate values?
??
11/30/2006 (6:54 am)
Ok I've installed mountEquipment from the resource at: http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=10304
and I'm using that for the moment instead of mountObject, and I've used some (offset calculating) code posted before by Mike Cozzolino so at the moment it looks like:
//-----------------------------Liver------------------------------------------------
datablock ShapeBaseImageData(LiverPic)
{
category = "Organs";
shapeFile = "~/data/shapes/organs/liver/liver4Cm.dts";
};
datablock ShapeBaseData(mesh_Liver)
{
//offset = $stickPos;
shapefile = "~/data/shapes/organs/liver/liver4Cm.dts";
rotation = "1 0 0 0";
emap = true;
};
datablock StaticShapeData(Liver)
{
category = "Organs";
shapeFile = "~/data/shapes/organs/liver/liver4Cm.dts";
image = LiverPic;
};
function Liver::onCollision(%this,%obj, %col, %pos, %normal)
{
%instrument = %obj.sourceObject;
if(%col.getType() & ($TypeMasks::PlayerObjectType |$TypeMasks::AIPlayerObjectType))
{
echo("Yip a player did it!");
%hitx = getWord(%pos,0);
%hity = getWord(%pos,1);
%hitz = getWord(%pos,2);
%mountx = getWord(%col.getSlotTransform(0),0);
%mounty = getWord(%col.getSlotTransform(0),1);
%mountz = getWord(%col.getSlotTransform(0),2);
echo("collision pos ="@%pos);
echo("Player Slot 0 ="@%col.getSlotTransform(0));
echo("Mount Pos = "@%hitx - %mountx SPC %hity - %mounty SPC %hitz - %mountz);
%stickPos = %hitx + %mountx SPC %hity - %mounty SPC %hitz - %mountz;
echo("Mount Pos = "@%stickPos);
mesh_liver.offset = %stickPos;
echo("liver Offset Value="@ mesh_liver.offset);
%col.mountEquipment(mesh_Liver, "mount0");
}
}BTW this is supposed to be (in the distant future) a surgical training tool fro a college project - in case you were wondereing about 'Liver' thing. My player is a surgical instrument like a tweezers!
However, At the moment when I collide with the Liver object a shapeBase Image of the Liver mounts to the player but not at the point of collision there is a big gap between the liver and the player,
This is the code that calculates the offset:
%stickPos = %hitx + %mountx SPC %hity - %mounty SPC %hitz - %mountz;This is what is confusing me now... Am I supposed to be getting the difference between the point of collision and the mount0 node of my player
What is the offset parameter for ? is it to transform from the origin of the object (Liver) by the offset coordinate values?
??
#13
@ mb: good job on visually explaining what is happening. From the STP snapshots, it does appear that your mountPoint Node in object is perhaps slightly offset from the actual cube mesh[underneath]? Is this the case? And when you mount the object in the engine; there is no offset? I'm intereseted, as I'm currently working on some mounting of my own and want to know ahead of time, what to be aware of. Thanks.
Hope some better aswers appear, I'm sure they'll surface. I'm always trying to learn as much as I can about how the engine is suppose to function. Everyone is doing something a little bit differenty and it becomes challenging to sift 'between the lines' and get what yourself is doing...;).
Cheers.
11/30/2006 (7:27 am)
@ Fiona: I'm curious, I understand the 'player' object is the tweezers. Is there any reason that the 'mounting' object[Liver in this case], needs to be mounted at the point of collision[of the tweezer mesh]? To me, it sounds like the board game "Operation", where you're extracting from the 'body' object, the organ of choice. If that's the case, and you want super dynamic mounting of the 'liver' object; Source code may need tweeking...? If you just want the liver object to mount to the tweezers and 'look' correctly mounted to the tweezers upon collsion; I think aligning the two shapes, and their mounting Nodes in your modelling program may be an 'easier' approach. Of course this will react as in default TGE like a weapon mounting...no smooth transition. One object pops out of existence and the new one pops into existence, perfectly aligned. I'm an artist, and it sounds as though you've added a Resource which I know nothing about. With that outline it should be fairly easy to get a much clearer anwer.@ mb: good job on visually explaining what is happening. From the STP snapshots, it does appear that your mountPoint Node in object is perhaps slightly offset from the actual cube mesh[underneath]? Is this the case? And when you mount the object in the engine; there is no offset? I'm intereseted, as I'm currently working on some mounting of my own and want to know ahead of time, what to be aware of. Thanks.
Hope some better aswers appear, I'm sure they'll surface. I'm always trying to learn as much as I can about how the engine is suppose to function. Everyone is doing something a little bit differenty and it becomes challenging to sift 'between the lines' and get what yourself is doing...;).
Cheers.
#14
I offset the node on boxB when I created the node. In-game there is a small gap between boxA & boxB. It looks like it works to me.
@ Fiona
I think what you trying to do is get the position of where the collision occurs. Then get the offset from the center of the object your mounting (tweezers) to where the collision occured. Then mount your liver to the center of your tweezers and use the offset to position the liver where the collision occured. Does this sound right?
11/30/2006 (8:26 am)
@RexI offset the node on boxB when I created the node. In-game there is a small gap between boxA & boxB. It looks like it works to me.
@ Fiona
I think what you trying to do is get the position of where the collision occurs. Then get the offset from the center of the object your mounting (tweezers) to where the collision occured. Then mount your liver to the center of your tweezers and use the offset to position the liver where the collision occured. Does this sound right?
#15
You are correct. I have discussed this with Fiona and my math skills are well pretty much non-existant. That is exactly what we want to do.
12/01/2006 (10:31 am)
@ mbYou are correct. I have discussed this with Fiona and my math skills are well pretty much non-existant. That is exactly what we want to do.
#16
Rex, mb - ye are totally right - I realised yesterday that I was calculating the offset for the wrong object - I finally got it working with -
for some reason
I really wanted to get this to work with mountObject though - mountEquipment / mountImage just aren't working out for many reasons including collisions, animations and the fact that before i mount the 'liver' to the player I have already mounted it (onload) to another object (an artery) so when I mount to an image - the image isn't mounted to the artery - :(
I may have to try change some source code to allow mountObject the have an offset parameter... but my C++ skills are not so great!
If anyone sees this thread and happens to have done this before - or knows how to do it, please let me know!!
Thanks everyone for your help on this anyway..Cheers,
Fi*
12/03/2006 (9:48 am)
Hi there,Rex, mb - ye are totally right - I realised yesterday that I was calculating the offset for the wrong object - I finally got it working with -
%offset = VectorSub( %liver.getPosition(), %player.getSlotTransform(0));
for some reason
%offset = VectorSub( %liver.getPosition(), %collisionPos);wasn't working but anyway not to worry - I have plenty more problems to think about! ;)
I really wanted to get this to work with mountObject though - mountEquipment / mountImage just aren't working out for many reasons including collisions, animations and the fact that before i mount the 'liver' to the player I have already mounted it (onload) to another object (an artery) so when I mount to an image - the image isn't mounted to the artery - :(
I may have to try change some source code to allow mountObject the have an offset parameter... but my C++ skills are not so great!
If anyone sees this thread and happens to have done this before - or knows how to do it, please let me know!!
Thanks everyone for your help on this anyway..Cheers,
Fi*
Community Manager Michael Perry
ZombieShortbus
mountObject vs mountImage
Using mountObject
StaticShape::onCollision
That last one has some sample code from me in it. The thing is, I ended up using an image to get proper mounting orientation, which was weird. My artist would show me the mounting in ShowTool (which looked perfect), yet staticShape can't handle mountObject in stock Torque for some reason. Hope this helps.