Game Development Community

Rigid Shapes collision

by Harley · in Torque Game Engine · 03/16/2005 (4:32 am) · 4 replies

Hi,
I have been trying to make a pool/snooker game using torque for the past couple of weeks and have decided to use the Rigid Shape class (http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=5495). At the moment I have just made it so that the balls can be pushed around by the player (temporary). My problem is that when the balls collide with each other they seem to rebound off at weird angles. The code i'm using in the onCollision method is below. I'm fairly new to vector math so someone with a little more experience in that area may see something that i'm doing wrong...

thanks guys in advance,
Harley.

function SnookerBall::onCollision(%this, %obj, %col)
{
if (%col.getDataBlock().getName() $= "SnookerBall")
{
// Apply an impulse to the object we collided with
%eye = VectorNormalize(%obj.getVelocity()); //PROBLEM HERE?? This was meant to get the direction of the ball

//How hard the ball is hit. TEMPORARY
%power = vectorLen(%obj.getVelocity());
%vec = vectorScale(%eye, %power);

// Heres the position and rotation
%trans = %col.getTransform(); .
%pos = getWords(%trans, 0, 2);

%col.applyImpulse(%pos,%vec);




}


}

#1
03/16/2005 (8:04 am)
Hey - I've tried getting 2 rigid shapes to collide too, and part of the problem is that onCollision is called on both the collider and the collided shape. Thus they both try to apply forces to each other making the outcome very hard to predict.

I never took it further than a few tests, so I didnt solve the problem.

Just to let you know. If you solve it, feel free to post a solution
#2
03/16/2005 (8:54 am)
Maybe apply different force based on the velocity and/or mass of the rigid shape.
#3
03/16/2005 (1:44 pm)
Well, it does make sense that onCollision is called on both. Each one will need to react to collision. Thing is, you'll need to transfer energy from the moving ball to the one that's still.

Also, be aware that you'll never have perfect spheres, since the collisions, AFAIK, are done against planes. And things will start to go mucky if you have a highly tesselated collision mesh (and even if it's highly tesselated, inaccuracies will still occur).

You need to implement perfect sphere collision. It's not that hard to collide a sphere against a plane, you'll just need to figure out where to insert such code (I have no idea).
#4
03/16/2005 (6:22 pm)
Thanks for the replies guys.

@Thomas - yep I think that may be the case too. Do you think that if the Rigid Shape class had a collisionTimeout function that would help? I've no idea how to do this, fairly new to Torque, but I can look into it if it might help.

@Manoel - I understand what you are saying and I agree that they both need to react to the collision. I will also look into the sphere collision, I think thats what I will need for what I am doing in the end anyway.

regards,
Harley.