Collisions Not Registering...?
by David Taylor · in Torque Game Builder · 12/01/2008 (5:49 pm) · 3 replies
I've been trying to work my way around this problem for a day and a half, and I've run out of ideas.
I have 4 balls on the screen - white, red, blue, and green. These are all under the same class but with different names, depending on colour.
If I shoot an extra ball, (as in, the 5th ball is a projectile), and I set the projectile image map as the white ball, attach collision routines to it, and so on, it collides with the 4 balls that were already there. (This is good.)
However, in the ball class, onCollision only gets called for the 4 balls that were already there, and not for the 5th ball that was created in game with the shoot behaviour. (This is bad.)
I tried mounting a trigger to one of the 4 balls to see if that would work, but I basically end up with the same result: balls bouncing against each other, but only the 4 balls are calling the onCollision function.
I think it's because the projectile is presumably not recognising itself as a member of the same ball class as the other 4. That's my best guess, anyway. How do I go about convincing each new projectile that is fired that it, too, is a ball, so that onCollision gets called by both objects in the collision?
(Even now, if the 2 white balls collide, and I call getName() on both the %srcObject and the %dstObject, only the ball that was already on screen before I started shooting returns the name.)
Many, many, many thanks in advance!
I have 4 balls on the screen - white, red, blue, and green. These are all under the same class but with different names, depending on colour.
If I shoot an extra ball, (as in, the 5th ball is a projectile), and I set the projectile image map as the white ball, attach collision routines to it, and so on, it collides with the 4 balls that were already there. (This is good.)
However, in the ball class, onCollision only gets called for the 4 balls that were already there, and not for the 5th ball that was created in game with the shoot behaviour. (This is bad.)
I tried mounting a trigger to one of the 4 balls to see if that would work, but I basically end up with the same result: balls bouncing against each other, but only the 4 balls are calling the onCollision function.
I think it's because the projectile is presumably not recognising itself as a member of the same ball class as the other 4. That's my best guess, anyway. How do I go about convincing each new projectile that is fired that it, too, is a ball, so that onCollision gets called by both objects in the collision?
(Even now, if the 2 white balls collide, and I call getName() on both the %srcObject and the %dstObject, only the ball that was already on screen before I started shooting returns the name.)
Many, many, many thanks in advance!
About the author
#2
So I've pulled that behaviour and am in the process of using scripting to generate the projectiles. I've got them shooting so far with the correct image map and very basic collisions, but not as the appropriate class. I'll keep working on it, but if I keep getting stuck, I'll come back here. :)
12/06/2008 (6:58 pm)
@Matt: That's not as dumb as a suggestion as you might think. In short, no, and obviously, that's a problem. I was using the 'shoots' behaviour which seems to duplicate the aspects of each new projectile, (image map, size, collisions, etc), but not as another iteration of the same class.So I've pulled that behaviour and am in the process of using scripting to generate the projectiles. I've got them shooting so far with the correct image map and very basic collisions, but not as the appropriate class. I'll keep working on it, but if I keep getting stuck, I'll come back here. :)
#3
So the ball::onCollision is only getting called when the projectile ball hits the original ball - but not when two projectile balls hit each other.
Does that make sense?
12/08/2008 (4:56 pm)
Okay, so I still can't get it to register itself as a ball. I have a ball class, with an onCollision call, but it still only gets called by the ball that I placed in the level builder - never by the projectile. If I type %projectile.class = ball, and then when the onCollision is called through the original ball, I ask it for the classes of both the two balls that have collided, it returns the word 'ball' for both of them. Great! But if I ask them for the object, the ball that was already in the level builder returns a string, and the projectile returns nothing.So the ball::onCollision is only getting called when the projectile ball hits the original ball - but not when two projectile balls hit each other.
Does that make sense?
Torque Owner Matt Grosse
%projectile = new t2dStaticSprite()
{
scenegraph = $myScene;
class = ball;
imagemap = ballImageMap;
};