New Dev Collision Questions
by Chris · in Torque Game Builder · 04/27/2009 (10:32 am) · 9 replies
Hey guys,
I apologize up front for a newbie questions, but I started with TGB a month or so ago and have gone through most of the tutorials and read a book or two. I decided it's about time that I try to make something on my own, so I'm making a simple "Pong" clone.
I've got the paddles and the ball in play and things are working fine with them, but I seem to be having problems with collisions on the top/bottom walls.
For the top and bottom I created two scene objects and made them both part of a "wallclass". I've set them to Send collisions with a "Bounce" response.
As for the ball, when it's created I have it set to both send and receive collisions, and have a "Bounce" collision response. Problem is, when the ball hits the walls, it just keeps going.
To make sure the collision was working, I set both the ball and walls to send a callback and put in a function that would Echo that the wall was hit onCollision and it is seeing the collision, I'm just not getting a bounce response.
Any ideas?
Thanks!
I apologize up front for a newbie questions, but I started with TGB a month or so ago and have gone through most of the tutorials and read a book or two. I decided it's about time that I try to make something on my own, so I'm making a simple "Pong" clone.
I've got the paddles and the ball in play and things are working fine with them, but I seem to be having problems with collisions on the top/bottom walls.
For the top and bottom I created two scene objects and made them both part of a "wallclass". I've set them to Send collisions with a "Bounce" response.
As for the ball, when it's created I have it set to both send and receive collisions, and have a "Bounce" collision response. Problem is, when the ball hits the walls, it just keeps going.
To make sure the collision was working, I set both the ball and walls to send a callback and put in a function that would Echo that the wall was hit onCollision and it is seeing the collision, I'm just not getting a bounce response.
Any ideas?
Thanks!
About the author
#2
Welcome to Torque, BTW!
04/27/2009 (4:58 pm)
Don't forget to turn on physics!! That should help the ball bounce.Welcome to Torque, BTW!
#3
04/27/2009 (5:48 pm)
Thanks! I did, and got it working, though I'm wondering if there's a wall to call out a sound file when the ball hits the worldlimits. I did see I can set a callback, which I did, but can't seem to get a function to kick off from the callback.
#4
Great job getting it working! Check out the onWorldLimit method... It's called when your object reaches its world limits
function Ball::onWorldLimit(%this, %mode, %limit)
{
// When the ball hits the world limits,do this....
}
04/28/2009 (6:35 pm)
Hi Chris,Great job getting it working! Check out the onWorldLimit method... It's called when your object reaches its world limits
function Ball::onWorldLimit(%this, %mode, %limit)
{
// When the ball hits the world limits,do this....
}
#5
I did have that function in place, come to find out, there was a problem with the sound file. I popped another sound file into that function and everything worked fine. Not sure what was wrong with the original .wav file, as it plays find outside TGB. But everything is working great.
04/29/2009 (7:35 am)
Thanks Johnny,I did have that function in place, come to find out, there was a problem with the sound file. I popped another sound file into that function and everything worked fine. Not sure what was wrong with the original .wav file, as it plays find outside TGB. But everything is working great.
#7
Before I had it coded so when the game board would load up, both the paddles would load and it would randomly pick one to mount the ball on for serving.
Since I've added the mainmenu level in, I'm now getting a "t2dSceneObject::mount() - Object '1343' is not in a SceneGraph!"" error on the mount command in this function.
I'm not sure if the object being referred to is the ball or paddle. Either way, both of them should already be in the scene and I'm not sure why adding the new main menu layer would cause that to blow up.
Any thoughts? :)
05/01/2009 (11:36 am)
Hmm, ran into another small snag, wondering if anyone has an idea. I had just about everything working fine, but I've since added a new level for a main menu. I've created the GUI and buttons that will kick off the actual game board.Before I had it coded so when the game board would load up, both the paddles would load and it would randomly pick one to mount the ball on for serving.
Since I've added the mainmenu level in, I'm now getting a "t2dSceneObject::mount() - Object '1343' is not in a SceneGraph!"" error on the mount command in this function.
function redPaddle::redprepBall(%this)
{
$ballLoaded = newBall($redPaddle.getPosition(),"0 0");
$theball.setCollisionActive(0,0);
$theball.mount($redPaddle, "-2.00 0.0");
$redballinPlay = 0;
}I'm not sure if the object being referred to is the ball or paddle. Either way, both of them should already be in the scene and I'm not sure why adding the new main menu layer would cause that to blow up.
Any thoughts? :)
#8
The newball function is in a different script file, but it is getting called correctly. Not really sure why this all works fine if I load up the game level directly, but if I load the game level through a menu screen the ball isn't in the $scenegraph.
05/02/2009 (7:54 pm)
Well, I've narrowed things down a bit. It's definitely something wrong with the ball creation. I've run some echo commands in the script. The error spits out on Line 5 of the code above, but the ball has been created in line 3. I ran some other echo's on the $theball and $redpaddle to see what object 1343 was, and it's the ball. Here's my newball function that is called in line 3.function newBall(%ballLoc,%ballVector) {
$theball = new t2dStaticSprite() {
scenegraph = $thescenegraph;
imageMap = "BallImageMap";
Position = "0 0";
size = "2.000 2.000";
class = "ballClass";
CollisionActiveSend = "1";
CollisionActiveReceive = "1";
CollisionPhysicsSend = "0";
CollisionPhysicsReceive = "0";
CollisionCircleScale = "1";
CollisionDetectionMode = "CIRCLE";
CollisionResponseMode = "BOUNCE";
CollisionCircleSuperscribed = "0";
};
$theball.setMass(10.8);
$theball.setRestitution(1.0);
$theball.setFriction(0);
$theball.setCollisionCallback(1);
$theball.setLinearVelocity(%ballVector);
}The newball function is in a different script file, but it is getting called correctly. Not really sure why this all works fine if I load up the game level directly, but if I load the game level through a menu screen the ball isn't in the $scenegraph.
#9
I added a "$thescenegraph = sceneWindow2D.getSceneGraph();" to the function that initialized the game play level and it's working like a champ. :)
05/02/2009 (8:02 pm)
Heh, amazing, the last sentences I typed out made something click. The ball was being loaded, but it was being loaded into another scenegraph because the only time I set $scenegraph was on the initial level load, which was now the main menu level.I added a "$thescenegraph = sceneWindow2D.getSceneGraph();" to the function that initialized the game play level and it's working like a champ. :)
Torque Owner Chris