OnCollision function, seperating players from bots.
by Logan Strunk · in Torque Game Engine · 12/20/2006 (6:34 pm) · 11 replies
I have doors in my game. Problem is, my bots can open them, and I don't want them to be able to. Doesn't make much sense that Zombies can open doors.
Anyways....Heres the function.
function door::onCollision(%this,%door,%col){
if (!%door.open){
%door.open=true;
%door.setthreaddir(0,"true");
%door.playthread(0,"open");
serverPlay3D(doorOpenSound,%col.getTransform());
%this.schedule(2000, close, %door,%col);
}
}
Now, someone on IRC suggested comparing the player class mask to "playerbody". The problem is, that my zombie bots inherit the player class.
Is there anyway to seperate the child from the parent? I'm using the AIGuards for the zombies ?
Theres one other way to do this, which involves giving every player a key, and the door checking for the key. But...I really don't want that for this game, and it seems like a bit of a "hack" to me. Is there any other way of doing this?
thanks guys.
Anyways....Heres the function.
function door::onCollision(%this,%door,%col){
if (!%door.open){
%door.open=true;
%door.setthreaddir(0,"true");
%door.playthread(0,"open");
serverPlay3D(doorOpenSound,%col.getTransform());
%this.schedule(2000, close, %door,%col);
}
}
Now, someone on IRC suggested comparing the player class mask to "playerbody". The problem is, that my zombie bots inherit the player class.
Is there anyway to seperate the child from the parent? I'm using the AIGuards for the zombies ?
Theres one other way to do this, which involves giving every player a key, and the door checking for the key. But...I really don't want that for this game, and it seems like a bit of a "hack" to me. Is there any other way of doing this?
thanks guys.
#2
12/20/2006 (7:41 pm)
Will that work for multiplayer games?
#3
12/20/2006 (7:46 pm)
Oh, and "%player.getControllingClient()>0" does not work. Any other ideas?
#4
I think it should work on any shapeBase object which has been set as a client's GameConnection control object, multiplayer or not.
Is your player mounted (so that it's not the control object)?
on edit:
Oh, I think in your example above, you'd check 'if(%col.getControllingClient()>0)'.
12/20/2006 (7:54 pm)
Hmm...are you sure '%whateverYourPlayerObjectIs.getControllingClient()>0' doesn't work? I use it myself, and I see it defined in shapeBase.cc around line 4244 or so (though I have a modified shapeBase.cc file, so the lineNumber might be different):ConsoleMethod( ShapeBase, getControllingClient, S32, 2, 2, "Returns a GameConnection.")
{
if (GameConnection* con = object->getControllingClient())
return con->getId();
return 0;
}I think it should work on any shapeBase object which has been set as a client's GameConnection control object, multiplayer or not.
Is your player mounted (so that it's not the control object)?
on edit:
Oh, I think in your example above, you'd check 'if(%col.getControllingClient()>0)'.
#5
Logan, to be clear, you want real players to open doors, but not AIPlayers ?
if that's the case, then yeah, some test along the lines of if (isObject(%col.getControllingClient())) should work.
12/20/2006 (9:36 pm)
.. what Brian said.Logan, to be clear, you want real players to open doors, but not AIPlayers ?
if that's the case, then yeah, some test along the lines of if (isObject(%col.getControllingClient())) should work.
#6
12/20/2006 (11:47 pm)
If(!%col.isAIControlled()) would work too.
#7
12/21/2006 (12:51 am)
Or if ( %player.getClassName () $= "Player" )
#8
I appreciate all the help guys, and I'll post again if I can't get this sucker working.
12/21/2006 (9:18 am)
Orion: Yep, my AI guys are zombies. Opening doors isn't something they should be able to do.I appreciate all the help guys, and I'll post again if I can't get this sucker working.
#9
:)
12/21/2006 (9:55 am)
Despite what you may have seen in movies in real-life zombies can open doors.:)
#10
that's why i always put zombie-proofing gadgets on all drawers & cupboards etc.
a clever zombie can still get at the cleaning products, but it helps a little bit.
12/21/2006 (10:02 am)
Hahaha.that's why i always put zombie-proofing gadgets on all drawers & cupboards etc.
a clever zombie can still get at the cleaning products, but it helps a little bit.
#11
That worked just fine. Thanks a ton guys.
Now I have a new problem though...
12/21/2006 (10:34 am)
If (isObject(%col.getControllingClient()))That worked just fine. Thanks a ton guys.
Now I have a new problem though...
Torque Owner Brian Hill
However, I think that you can use the 'getControllingClient()' function to return the same information with more certainty, ie., "if(%player.getControllingClient()>0)" .