Game Development Community

Ball collision question [Resolved, thanks Simon]

by Cosmic Logic · in Torque Game Builder · 03/24/2009 (9:23 pm) · 4 replies

Hey,

I've got a setup that I need two lacross players passing a ball.

I'll give you a general rundown on how it's implemented before I get in to the problem.

The player that the user controls has a behavior that deals with moving and the pass/shoot button. As soon as the ball collides with another player, the source player has that behavior removed, then it is added onto the collided(word?) player. This is my collision method:
if(%dstObj.class $= "Player")
      if(%dstObj.getName() !$= %srcObj.source){
         %srcObj.setAtRest();
         %srcObj.mount(%dstObj,getWord(%dstObj.LinkPoints,0),getWord(%dstObj.LinkPoints,1),0, true, true, true, true);
         %srcObj.setCollisionSuppress(true);
         %srcObj.source.losesBall();
         %dstObj.receivesBall();
      }

The only problem I'm having with this set up is that if the pass misses, or the ball is shot at the net, the player who shot the ball cannot pick it up elsewhere, it would have to rely on one of the other AI players to pick up the ball, therefore granting that player user control. *note: the collisionsupress function is called just so the mounted ball isn't constantly colliding with the player, as soon as the pass/shoot function is called, the supression is removed.*

I could also get rid of the if(%dstObj.getName() !$= %srcObj.source) but the ball sprite is mounted onto my player sprite. So as soon as the ball is passed it collides with the player that shot it immediately.

I've done some programming before, but this is my first game project rather than application and the train of thinking is new to me. If anyone has any tips on how to make this work that would be awesome :)

#1
03/27/2009 (10:38 am)
how about as soon as the player throws the ball the ball object gets called with something like:
$BallObject.hasBeenThrown();

function ballclass:hasBeenThrown(%this)
{ %this.source = -1;
}

to indicate that once thrown the ball has no owner.
#2
03/27/2009 (10:46 am)
Unfortunately I've tried something like that, but it mounts in the top left corner of my source sprite, so if it tries to travel to the bottom right direction it makes a whole bunch of collisions in that direction. So, as soon as the pass function is called, if it has no owner it gets caught by the source player on it's way across it's sprite.
#3
03/27/2009 (11:14 am)
Ah ok, so how about scheduling the call for half a second (or so) later? Giving the ball to leave the source player's sprite.

#4
03/27/2009 (8:11 pm)
I've tried that as well. It worked a bit, except if the player being passed to was too close it wouldn't pick it up.

Though, if I use the schedule in a different way it might work. I'll try adding a hasBall method into the player's class and make the schedule make the thrower's hasBall variable false after half a second the ball will still properly collide with the next player and not be interrupted.

I'll post a resolved notice if it works.

UPDATE: I've got my passing working. Thanks for the tip, that got my brain thinking in the right direction.

If anyone has a problem like this and want me to go into more solution detail, just let me know