Game Development Community

Overlap and Collisions

by Bob Verity · in Torque Game Builder · 06/08/2010 (5:36 am) · 2 replies

Hi,

I am relatively new to the Torque world so can I start by saying congratulations on creating such a neat product! I am really enjoying messing around with the Torque 2D demo and will no doubt buckle soon and buy the full thing :)

My problem is a follows. I have two characters in an RPG-style game (for all intents and purposes they are circles) that the player can send around the level using my own astar pathing algorithm. If the circles collide then they first stop, before re-evaluate their paths taking into account each other as additional obstacles.
The pathing is all working fine, but the collision procedure is giving me grief. When the circles collide the collision procedure is called over and over again before the re-pathing kicks in and the characters move apart, causing my memory-hungry pathing function to bring the game to a standstill!

I have tried disabling collisions on the circles themselves and using mounted triggers instead, allowing me to use OnEnter rather then OnCollision. Although this worked in the sense that the collision was only called once, it caused all sorts of other problems downstream which I'd rather not have to deal with. What I really need is for the circles to exclude each other - I have seen mention of a "SolveOverlap" procedure in another thread, but cannot find a complete description anywhere.

Any pointers would be greatly appreciated

#1
06/08/2010 (6:20 am)
Disable collisions when objects first collide, enable when your repathing code kicks in.

onCollision:
%obj.setCollisionActive(false, false);  

repathing code:
%obj.setCollisionActive(true, true);

OR

Use dynamic variables as flags:

E.g:
onCollision:
%srcObject.collided=true
%dstObject.collided=true


repathing:
%srcObject.collided=false
%dstObject.collided=false

if(%srcObject.collided==false&&%dstObject.collided==false) {
   //your code here
}
#2
06/09/2010 (6:57 am)
Cheers Aditya,

I don't think the first method will work in my game because the characters will eventually need to able to collide with other things too, but the dynamic variables plan sounds good. I'll have a mess around later :)