Grab the Flag
by Quest Johnny · in Torque Game Engine · 09/18/2004 (7:20 am) · 7 replies
Hello folks,
Ok, here's my little problem, and it's a fun-script-logic problem not a deep techy one...
I have implemented a "grab the flag" feature in my game: If you touch another player who has the flag, you grab the flag.
The problem (naturally) is that he's also touching you, and you're touching him, so the system does a lot of very fast flip-flopping and it's random who actually winds up with the flag. More often than not, it appears nobody grabs the flag, but the log says otherwise.
Solutions:
1. Implement a no-grab-backs system.. but after a time, the same player COULD grab it back, no?
2. Implement a timer that when the flag is grabbed, it cannot be retaken for some time x.. but.. what happens if a 3rd player is touching..
Any ideas from common-game-wisdom?
Ok, here's my little problem, and it's a fun-script-logic problem not a deep techy one...
I have implemented a "grab the flag" feature in my game: If you touch another player who has the flag, you grab the flag.
The problem (naturally) is that he's also touching you, and you're touching him, so the system does a lot of very fast flip-flopping and it's random who actually winds up with the flag. More often than not, it appears nobody grabs the flag, but the log says otherwise.
Solutions:
1. Implement a no-grab-backs system.. but after a time, the same player COULD grab it back, no?
2. Implement a timer that when the flag is grabbed, it cannot be retaken for some time x.. but.. what happens if a 3rd player is touching..
Any ideas from common-game-wisdom?
About the author
#2
09/18/2004 (8:48 am)
I would use #1 but have it so NO ONE could grab the flag until the schedule "releases" it. In this way, you solve problem #2 where another person nearby could grab it immediately. Depending on the pace of your game, the "hold" duration could be anywhere from a few tenths of a second to a few whole seconds.
#3
UPDATE: Heh.. I implemented the "game flag delay" solution, and it does work.. but backwards. You can GIVE the flag to somebody, but not TAKE it! I'll try to figure out why .. ;)
09/18/2004 (10:13 am)
That's a great idea!UPDATE: Heh.. I implemented the "game flag delay" solution, and it does work.. but backwards. You can GIVE the flag to somebody, but not TAKE it! I'll try to figure out why .. ;)
#4
09/18/2004 (11:44 am)
The person who LOSES the flag should be scheduled NOT to be able to grab again for X number of seconds. That solves all your problems because there can be no flip-flopping, and if some guy jacks you a tenth of a second after you jack someone else, then to bad, so sad.
#5
for the intended design, so-be-it. But that may not be the case. I don't know enough about the situation.
@Andrew: I don't understand how it could be backwards. The logic I was thinking of was that the flag couldn't transfer *at all* within X seconds - either give or steal. The schedule() would clear the flag in X seconds and then it would be up for grabs again to whoever.
I tried something like this for a football mod in CoD. Got it working, but CoD is *krap* for modding, so I gave up due to some other features that just wouldn't work. But the basic idea of the "ball" passing was the same.
09/18/2004 (5:26 pm)
@Gonzo: It may be a gameplay decision whether jacking within 1/10 second is allowed. If it is interesting gameplay for the intended design, so-be-it. But that may not be the case. I don't know enough about the situation.
@Andrew: I don't understand how it could be backwards. The logic I was thinking of was that the flag couldn't transfer *at all* within X seconds - either give or steal. The schedule() would clear the flag in X seconds and then it would be up for grabs again to whoever.
I tried something like this for a football mod in CoD. Got it working, but CoD is *krap* for modding, so I gave up due to some other features that just wouldn't work. But the basic idea of the "ball" passing was the same.
#6
According to what I see in the code, it's a grab, not a give. The grabbable timeout works perfectly tho. The flag is "given" perfectly each time.. Now if I can only figure out how to reverse it :)
However, Gonzo's idea is better. After I try to figure this, I might implement that instead.
UPDATE: I just retested it,.. I realized the code wasn't being updated.. there was a dumb syntax error (a ; at the end of a function) so the updated script wasn't actually loading. With the check on the flag it DOES work. Not.. perfectly, but.. works :)
09/19/2004 (7:18 am)
I'm at a loss to understand it myself, Eric!According to what I see in the code, it's a grab, not a give. The grabbable timeout works perfectly tho. The flag is "given" perfectly each time.. Now if I can only figure out how to reverse it :)
However, Gonzo's idea is better. After I try to figure this, I might implement that instead.
UPDATE: I just retested it,.. I realized the code wasn't being updated.. there was a dumb syntax error (a ; at the end of a function) so the updated script wasn't actually loading. With the check on the flag it DOES work. Not.. perfectly, but.. works :)
#7
Just add this function to your player.cs in your server folder...
Then when the player that has the flag drops it(gives it away, whatever) immediately after the drop set the player grab flag to false. Then schedule that player to be reset after x seconds(2 seconds in my example). Something like this....
{
stuff happens
player drops flag
%player.canGrabFlag = false;
%player.schedule(2000, "flagGrabReset");
}
And of course, wherever a player is eligible to pick up a flag(collision) you'll just need to check if the player can grab it...
Edit: If you use this method, make sure that every new player is initialized with %player.canGrabFlag = true; when they first start out or nobody will be able to grab one, lol.
09/19/2004 (3:53 pm)
My way would be pretty easy...Just add this function to your player.cs in your server folder...
function Player::flagGrabReset(%player)
{
%player.canGrabFlag = true;
}Then when the player that has the flag drops it(gives it away, whatever) immediately after the drop set the player grab flag to false. Then schedule that player to be reset after x seconds(2 seconds in my example). Something like this....
{
stuff happens
player drops flag
%player.canGrabFlag = false;
%player.schedule(2000, "flagGrabReset");
}
And of course, wherever a player is eligible to pick up a flag(collision) you'll just need to check if the player can grab it...
if(!%player.canGrabFlag) { return; }Edit: If you use this method, make sure that every new player is initialized with %player.canGrabFlag = true; when they first start out or nobody will be able to grab one, lol.
Torque Owner Very Interactive Person
This way, if player collides and his speed is high enough the flag is swapped, but becuase of the collision the speed is reduced and the second time it doesn't execute the code anymore.
I'm using a similar system in my car game for a similar problem.