Game Development Community

Collision & Fish Game Tutuorial

by Jeff Williams · in Torque Game Builder · 09/10/2008 (9:05 pm) · 5 replies

I am having an issue with the collision code on the fish game tutorial. Everything has been working fine up until now. I searched the forum and found where a few other people have had nearly the same problem as me but they never received an answer as far as I can tell.

I am on step 5 of the Fish Game Tutorial which is where the food is added. I have added the food, turned on the proper collision buttons for both the fish and the fish food, set up the proper collision box for the fish (4 point rectangular poly). I made the script changes as well. When I run the tutorial the food bubble passes right through the fish and never respawns until it reaches the end of the world limit.

Here is the 'onCollision' code that I have:

function FishFood::onCollision(%scrObject, %dstObject, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts)
{
echo ("===== In the FishFood::onCollision function =====");
echo ("===== The %srcObject.class object is " @ %srcObject.class);
echo ("===== The %dstObject.class object is " @ %dstObject.class);
echo ("===== The %contactCount object is " @ %contactCount);
echo ("===== The %contacts object is " @ %contacts);
echo ("===== End of echo statements. =====");

if(%dstObject.class $= "PlayerFish")
{
%srcObject.spawn();
}
}


This produces the following output in the log file:

Compiling C:/Documents and Settings/Jeff/My Documents/TGB/MyGames/MyFishGame/game/data/levels/MyFishLevel.t2d...

Loading compiled script C:/Documents and Settings/Jeff/My Documents/TGB/MyGames/MyFishGame/game/data/levels/MyFishLevel.t2d.

===== In the FishFood::onCollision function =====
===== The %srcObject.class object is L

#1
09/11/2008 (3:31 am)
Hi, I had the same issue when I first did that tutorial but for me it was not an issue with the coding so I can not say if your code is causing the problem.

What caused my problem was the collision polygon, make sure the superscribe ellipse is unchecked in the collision tab.

Im not sure if this is the same problem you are having as me but I hope it helps
#2
09/11/2008 (4:48 am)
Thanks for the reply.

In my case that check box is not checked for either the bubble or the fish I am using.

On the bubble (food) I have the following checked:

Send Collision
Receive Collision
Callback

and the detection mode is Circle.

On the fish I have these checked:

Send Collision
Receive Collision

My detection mode is Polygon.

In both cases I have the collision response set to clamp
#3
09/26/2008 (5:35 am)
Hey ughh I think I found your problem.. I had this to :D I fixe it because the code that came with the tutorial has...

function FishFood::onCollision(%scrObject, %dstObject, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts)
{
echo ("===== In the FishFood::onCollision function =====");
echo ("===== The %srcObject.class object is " @ %srcObject.class);
echo ("===== The %dstObject.class object is " @ %dstObject.class);
echo ("===== The %contactCount object is " @ %contactCount);
echo ("===== The %contacts object is " @ %contacts);
echo ("===== End of echo statements. =====");

if(%dstObject.class $= "PlayerFish")
{
%srcObject.spawn();
}
}


This produces the following output in the log file:

Compiling C:/Documents and Settings/Jeff/My Documents/TGB/MyGames/MyFishGame/game/data/levels/MyFishLevel.t2d...

Loading compiled script C:/Documents and Settings/Jeff/My Documents/TGB/MyGames/MyFishGame/game/data/levels/MyFishLevel.t2d.

===== In the FishFood::onCollision function =====
===== The %srcObject.class object is L

Well atleast this came with mine lol...

The problem is here
function FishFood::onCollision(%scrObject, %dstObject, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts)
and here...
if(%dstObject.class $= "PlayerFish")
{
%srcObject.spawn();
}
}

Notice the difference?

the %scrObject in the FishFood::onCollision(%srcObject and the %srcObject.Spawn(); in the if statement...

All you need to do is change the if statement from
if(%dstObject.class $= "PlayerFish")
{
%srcObject.spawn();
}
}

to

if(%dstObject.class $= "PlayerFish")
{
%scrObject.spawn();
}
}

This is what worked for me but I do not know if it will work with you but hey give it a try :D
#4
06/27/2009 (7:46 pm)
Thought I'd tell you what just fixed my problem. I had this exact issue. All I did was set a poligon around the bubble (fishfood) and instead of using circle I used poligon in the detectionmode.

Issue resolved...
#5
02/05/2012 (3:13 am)
I had a similar problem. I stumbled across something called "Debug Rendering" in the edit menu. One of the boxes says "Collision Bounds". By checking it, you can see what the collision for your game is.

My problem was that "custom" was somehow removing all collision from my PlayerFish. I could see this problem with debug mode, and fixed it by changing the PlayerFish collision to "Polygon", which still seems to support custom polygons. I can't guarantee that's your problem.

Keep an eye open for typos in the script too, if that did help.