Colliding with mounted objects: solved (I think)
by Daniel Buckmaster · in Torque Game Engine · 12/19/2009 (11:22 pm) · 9 replies
Try this: go into starter.fps, Barebones, world editor creator, and add a Tree2StaticShape. Mount it to the Player using the console. Try to run around a bit - you keep hitting the collision mesh of the tree mounted to the character.
To fix: add this at the top of ShapeBase::buildConvex:
That means that ShapeBase objects will check to see who is requesting their collision information; if it's an object they're mounted to (or the object that object is mounted to, etc.), then they refuse to give it, meaning that no collision happens. Other objects can still collide with the mounted object (so if you mount the tree to yourself and stand in Kork's way, he collides against the tree before he reaches you).
Note: I think some classes override buildConvex, so you'll have to put this code in a few other places as well. I haven't found any problems with it, but my testing has been pretty limited.
To fix: add this at the top of ShapeBase::buildConvex:
if (mShapeInstance == NULL)
return;
//ADD: ------->
// If we're mounted to them, don't give them anything!
ShapeBase* obj = this;
while(obj->mMount.object)
if((SceneObject*)obj->mMount.object == convex->getObject())
return;
else
obj = obj->mMount.object;
//<------- END
// These should really come out of a pool
mConvexList->collectGarbage();That means that ShapeBase objects will check to see who is requesting their collision information; if it's an object they're mounted to (or the object that object is mounted to, etc.), then they refuse to give it, meaning that no collision happens. Other objects can still collide with the mounted object (so if you mount the tree to yourself and stand in Kork's way, he collides against the tree before he reaches you).
Note: I think some classes override buildConvex, so you'll have to put this code in a few other places as well. I haven't found any problems with it, but my testing has been pretty limited.
About the author
Studying mechatronic engineering and computer science at the University of Sydney. Game development is probably my most time-consuming hobby!
#2
12/21/2009 (5:17 pm)
Quote:Now, if you can add this to shapeBaseImage! so weapons don't slide from the mount[n] when 'they' collide with something....like a DIFF! LOLThat shouldn't be too difficult - but it's nothing to do with the collision system, I think images use raycasts to displace themselves when penetrating a wall. But I thought that behaviour was disabled if the weapon didn't have a 'retract' node (or something with a name like that).
#3
To remove the displacement completely, you could remove the Player::calcClassRenderData() function so mWeaponBackFraction always returns 0.
12/21/2009 (5:46 pm)
I'm guessing that would be the mounted image displacement code in player.cc Player::renderMountedImage()To remove the displacement completely, you could remove the Player::calcClassRenderData() function so mWeaponBackFraction always returns 0.
#4
Rex: you flatter me ;)
12/21/2009 (6:50 pm)
Yep, that's what I was thinking. I thought there was a lot more complex stuff with getRetractionTransform, but it seems like mWeaponBackFraction is the crux of it all.Rex: you flatter me ;)
#5
Just realised that this is a more friendly way to do it, since mMount is declared as protected. So Player couldn't access it. I thought 'protected' meant only derived classes could access the variable... ah well.
12/23/2009 (10:44 pm)
It's really only Player and Item that have their own buildConvex method to worry about - just do the same as I did for ShapeBase::buildConvex and you'll be right.Just realised that this is a more friendly way to do it, since mMount is declared as protected. So Player couldn't access it. I thought 'protected' meant only derived classes could access the variable... ah well.
// If we're mounted to them, don't give them anything!
ShapeBase* obj = this;
while(obj->getObjectMount())
if((SceneObject*)obj->getObjectMount() == convex->getObject())
return;
else
obj = obj->getObjectMount();
#6
Daniel, sorry to go off topic. Thanks, that code works perfectly.
01/28/2011 (2:46 am)
Rex, If your interested in the weapon pushback problem (Which really annoyed me too, Lol) I`ve removed that code, and added a new state transition on the image called `StateTransitionOnInWall` and `StateTransitionOnOutWall` so you can basically do whatever you want from there. I play a weaponImage animation from the state machine and then call a script from the state machine to set an ArmThread of the player holding his weapon up by his side(Like in crisis). I was thinking of doing a resource! What do you think?Daniel, sorry to go off topic. Thanks, that code works perfectly.
#7
Not only do you have a solution for the 'pushback' issue; you've coupled it with a nice 'triggerable' effect on the Player object...nice.
How well does this work over the network in 3rdPerson??
The whole 'pushback' thing; I 'think' had to happen, otherwise I was finding you basically have a 'wall hack' without it, the weaponImage clips thru the wall and you can fire without entering a building[DIFF]. At least in the earlier version of TGE.....what the 'retraction' should do is stop the player's movement code and not allow the player object to advance, pushing the weapon up the arm...hey, it was 1999....
01/28/2011 (7:53 am)
Yes, demonstrating the animations of armThread via a cmd thru the State Machine of the ShapeBaseImage is something that Torque really needs, Hedd!Not only do you have a solution for the 'pushback' issue; you've coupled it with a nice 'triggerable' effect on the Player object...nice.
How well does this work over the network in 3rdPerson??
The whole 'pushback' thing; I 'think' had to happen, otherwise I was finding you basically have a 'wall hack' without it, the weaponImage clips thru the wall and you can fire without entering a building[DIFF]. At least in the earlier version of TGE.....what the 'retraction' should do is stop the player's movement code and not allow the player object to advance, pushing the weapon up the arm...hey, it was 1999....
#8
That wall-hack was the reason I did it, it was the wall-Hack or the weapon push back, an I wasnt happy with either.
I`ll get the resource typed up then! Would you be willing to test the network side for me. Its for TGE 1.5.2.
01/29/2011 (4:31 am)
I`m not sure about the over the network, as my game is one player only at the moment, but I cant see that there would be a problem. That wall-hack was the reason I did it, it was the wall-Hack or the weapon push back, an I wasnt happy with either.
I`ll get the resource typed up then! Would you be willing to test the network side for me. Its for TGE 1.5.2.
#9
www.garagegames.com/community/resources/view/20798
01/29/2011 (7:59 am)
Its Up. Just waiting for it to be approved.www.garagegames.com/community/resources/view/20798
Torque Owner Rex
BrokeAss Games
I really enjoy your Threads and Postings, Daniel. You seem to sort thru Torque Script and code with comfort and share your knowledge to the rest of the Community. For example, this topic.
This is something that I would want to utilize, as the stock engine doesn't seem to use this approach.
Now, if you can add this to shapeBaseImage! so weapons don't slide from the mount[n] when 'they' collide with something....like a DIFF! LOL