Colliding against mounts
by Daniel Buckmaster · in Torque Game Engine · 03/24/2007 (7:51 am) · 18 replies
I'm using an onCollision callback to mount a weapon on my player when the player runs into it. I was under the impression that mounted objects do not collide with whatever they're mounted to, and this has been the case in the past. However, after some recent changes to inventory scripts, mounted objects are now colliding with my player. Even if I don't ecexute the scripts I changed, the problem still occurs.
Basically, I can move two directions out of four. The other two directions will simply not work.
Could this be a problem with scripts? Or have mice been running riot inside my torqueDemo.exe?
Basically, I can move two directions out of four. The other two directions will simply not work.
Could this be a problem with scripts? Or have mice been running riot inside my torqueDemo.exe?
About the author
Studying mechatronic engineering and computer science at the University of Sydney. Game development is probably my most time-consuming hobby!
#2
With regards to your first problem, mounted object do collide with the objects they're mounted to. The only reason why this wouldn't happen (to my knowledge) is when the mounted object has no collision mesh.
You mention that you made changes to inventory scripts - what changes did you make? Those changes may have caused the object to start using its collision mesh (if it has one).
mountObject should work all the time, unless you've had a tinker with the source code. Check that you're calling it properly, and that the mounted object exists and that there is a suitable mountPoint for it.
--Amr
03/25/2007 (5:35 pm)
Hello Daniel,With regards to your first problem, mounted object do collide with the objects they're mounted to. The only reason why this wouldn't happen (to my knowledge) is when the mounted object has no collision mesh.
You mention that you made changes to inventory scripts - what changes did you make? Those changes may have caused the object to start using its collision mesh (if it has one).
mountObject should work all the time, unless you've had a tinker with the source code. Check that you're calling it properly, and that the mounted object exists and that there is a suitable mountPoint for it.
--Amr
#3
03/26/2007 (11:44 am)
Well, I wrote my own inventory scripts from scratch. I can post them here if you want - basically, there's a function that looks at the player's inventory (an array), finds an appropriate slot, and sets the value at that index to the weapon's handle. Then there's a function that goes through all the slots and mounts the objects where they should be mounted. I think that function is the most relevant:function Actor::updateInventory(%this,%obj)
{
for(%i = 0; %i < %this.numInvSlots; %i++) //For each inv. slot
{
if(%obj.slots[i] != null) //If there's an object in this slot
{
%obj.unmountObject(%obj.slots[i]); //Unmount it
if(%obj.currentSlot == i) //If this slot is selected
{
%obj.mountObject(%obj.slots[i],%this.handMount); //Mount on the hand
}
else
{
%obj.mountObject(%obj.slots[i],%this.inventoryMounts[i]); //Mount in the appropriate inventory slot
}
}
}
}
#4
Reckon I could see your mounted object model?
--Amr
03/26/2007 (11:53 am)
OK well, if your mounted objects are colliding with the player then the objects will have collision boxes on them, which you need to remove. Alternatively, if you need the collision boxes, try mounting your objects as ShapeBaseImageData objects - Images do not collide with the player, even if they have collision boxes.Reckon I could see your mounted object model?
--Amr
#5
03/26/2007 (12:15 pm)
I'm trying to avoid the ShapeBaseImage system as much as possible. The thing I don't understand is why it's not working now when it worked perfectly before. And no, no engine changes were made. Maybe I should just re-download and try again with the scripts.
#6
--Amr
03/26/2007 (12:17 pm)
Have you checked the models for your mounted objects? See if you can remove their collision meshes.--Amr
#7
03/27/2007 (9:11 am)
I know they're exporting with collision meshes, and I can remove them, but will onCollision still work with no collision mesh?
#8
--Amr
03/27/2007 (9:16 am)
I think onCollision will work, but I'm not sure whether it will use the shape's centroid for collision or the bounding box. I'm not 100% sure, so it's best you give that a quick test yourself. Just out of interest, can you describe what the mounted items will dothat requires onCollison? --Amr
#9
EDIT: I tried using no collision mesh, but no collision is registered with the shapes. Is there a way to disable and enable collision dynamically?
03/29/2007 (10:01 am)
The items I'm mounting are the weapons. I'm trying to implement a weapon system completely removed from Torque's ShapeBaseImage style. Basically, when you run into a weapon entity, you store its handle in an array and from then on the owner of the weapon says what to do with it - mounting it to carry it around and so on. My project has a huge variety of weapons at the moment, so Torque's default system would be a huge pain for me.EDIT: I tried using no collision mesh, but no collision is registered with the shapes. Is there a way to disable and enable collision dynamically?
#10
--Amr
03/29/2007 (1:53 pm)
Fair enough - I would say you probably won't need the collison meshes then - even if you create your model without collison meshes, Torque will still be able to collide with it (either using the bounding box or the centroid).--Amr
#11
By the way, thanks for all the help :)
04/05/2007 (3:56 am)
...with an engine code change, I guess?By the way, thanks for all the help :)
#12
I don't think you need engine changes - I remember the first time I made my own Item objects, I didn't even know about collision meshes in models, and my items collided just fine with the player.
I've just done a quick test, created a model with no collision mesh and added it as an ItemData object and also as a StaticShapeData. I was able to collide successfully with the centre of the ItemData object, but not the StaticShapeData object.
--Amr
04/05/2007 (4:28 am)
You're welcome!I don't think you need engine changes - I remember the first time I made my own Item objects, I didn't even know about collision meshes in models, and my items collided just fine with the player.
I've just done a quick test, created a model with no collision mesh and added it as an ItemData object and also as a StaticShapeData. I was able to collide successfully with the centre of the ItemData object, but not the StaticShapeData object.
--Amr
#13
04/05/2007 (7:03 am)
.
#14
I'm not even sure if my final game will require collision against items. I'm thinking of doing pickup with a keystroke - so when you hit 'E', whatever you're looking at is picked up. But for other games, and testing for now, I'd like to have collision pickups.
04/05/2007 (6:02 pm)
But the problem is that when the player collides with the mount, it stops him moving as if he'd hit a wall. I don't have control over that.Quote:I've just done a quick test, created a model with no collision mesh and added it as an ItemData object and also as a StaticShapeData. I was able to collide successfully with the centre of the ItemData object, but not the StaticShapeData object.That's very interesting. I'll try using ItemData instead. I'm away from my home comp at the moment, though, so it'll take a while.
I'm not even sure if my final game will require collision against items. I'm thinking of doing pickup with a keystroke - so when you hit 'E', whatever you're looking at is picked up. But for other games, and testing for now, I'd like to have collision pickups.
#15
04/05/2007 (8:53 pm)
.
#16
04/06/2007 (12:28 am)
Quote:In eg, you may want to ignore collisions against itemData objects, while not against staticShape and interior objects.I think that's already the case - it would seem that the engine already reacts this way from Amr's and my experiences. But I get what you mean now.
#17
Just done a quick test, and providing you don't have a collision mesh on your shape, you should be able to mount it on your player and move around OK.
--Amr
04/06/2007 (7:50 am)
Hello Daniel,Just done a quick test, and providing you don't have a collision mesh on your shape, you should be able to mount it on your player and move around OK.
--Amr
#18
04/06/2007 (8:33 am)
.
Torque Owner Daniel Buckmaster
T3D Steering Committee