Game Development Community

Collision detection is inconsistent

by Jereis Zaatri · in iTorque 2D · 09/05/2010 (12:23 am) · 8 replies

It seems iTGB does not run out of things to get on my nerves with 0_0!!!. Now collision detection is acting up. In this case one object keeps going into the other and then bounces out. The object that keeps going into the other has a constant force down (towards the object) and right. I've double checked the border lines of both and clearly one is entering the other. The animation is of a pig running off a ledge, but the pig is going into the ledge a number of times (almost the entire pig sinks in).

Here's code involved:

new t2dAnimatedSprite(piggy) {
animationName = "PRunS";
canSaveDynamicFields = "1";
class = "EscapingPig";
Position = "-233.500 -540.000";
size = "167.000 100.000";
Layer = "3";
CollisionActiveSend = "1";
CollisionActiveReceive = "1";
CollisionGroups = "1";
CollisionLayers = "1";
CollisionCircleScale = "140";
CollisionMaxIterations = "3";
CollisionPolyList = "-0.103 -0.845 0.535 -0.746 0.854 -0.082 0.422 0.845 -0.584 0.836 -0.722 -0.057";
UsesPhysics = "1";
ConstantForce = "990.000 9990.000";
LinearVelocity = "30.000 0.000";
mountID = "4";
};

new t2dSceneObject(TableTop) {
canSaveDynamicFields = "1";
Position = "-50.519 -336.379";
size = "471.039 102.758";
CollisionActiveSend = "1";
CollisionActiveReceive = "1";
CollisionGroups = "1";
CollisionLayers = "8";
CollisionCircleScale = "100";
CollisionMaxIterations = "3";
Immovable = "1";
mountID = "9";
};



Either this is a bug or there's something about collisions and physics that I don't understand yet.

#1
09/05/2010 (3:18 am)
So the pig is sinking into the ground he should be just running on? If so, yah, I have noticed similar things. One thing you could do is...

if pig touching ground, constant force on pig = 0.




If not touching ground constant force X... or Y in this case.
#2
09/05/2010 (6:03 am)
It's one of those collision issues with TGB. What I normally do is add a trigger, say at the ground, and if the piggy enters this trigger, the trigger will reverse the piggy's constant force.
#3
09/05/2010 (8:10 am)
Not sure if this is the same problem, but in the beginning I had problems with multiple collisions causing things to stick together. A solution I found was to disable collisions for a few milliseconds immediately after a collision occurs. Inside the collision callback I add something like:

%object.setCollisionActive(0,0);
%object.schedule(10, "makeHittable");

and then I have a "makeHittable" member function that enables collisions 10ms later:

function objectClass::makeHittable(%this)
{
%this.setCollisionActive(0,1);
}

This has helped to solve a lot of my collision issues.
#4
09/05/2010 (12:47 pm)
Hi Jereis, a couple of things ... you have maxIterations set to 3, do you need three? What happens if you set it to 1?

You have both objects set to send and receive, I find most of my collision issues are solved by carefully working out which object should send a collision and which should receive. I know from experience that having both will cause issues.

As your table top doesn't move I would set that to receive only.

"Object's can both collide with other objects and be collided with by other objects. Setting an object to send collisions makes it able to collide, and setting an object to receive collisions makes it able to be collided with. So, an object that is sending collisions will only be able to collide with objects that are receiving collisions and vice versa."
#5
09/06/2010 (9:53 am)
I've tried your solution Scott, but the problem still happens. I've resolved the problem by using a bunch of moveTo calls that follow one after the other. There's few situations that my game needs the use of constant force, so I should be able dodge this problem. It would be nice to see a new version of iTGB that resolves this dilemma, I've had enough hair pulling situations with iTGB. I'm hoping to get my game out late Winter to early Spring.
#6
09/07/2010 (8:13 am)
I understand your frustrations. I've spent a lot of time creating workarounds for a lot of things, but there is usually a workaround for most problems. I don't think these things are issues with iTGB though, I think they are just issues that occur with the way we implement our games, and I'm sure game developers experience different issues depending on what we are trying to do. For example, I have a ball that bounces around and collides with many different types of objects, and the main problem that I've experienced was the sticking problem where I had objects bouncing back and forth in an endless loop making them appear to be stuck. I think your problem is just a result of what you are trying to do, versus what the engine provides. I bet most game engines have their own particular quirks, and subsequently their own problems. Workarounds are something that we just have to come up with whenever we experience a unique problem, and in a way this is one of the things that makes it interesting working with a third party game engine. Yes it is a pain, but it can also be fun sometimes.
#7
09/07/2010 (1:08 pm)
I merged the physics changes from TGB 1.7.5 in and it stopped having objects sticking into each other. I was having issues with restitution settings as well, as in they really didn't seem to do anything. So, if you decide to merge stuff, be aware that your physics are probably going to feel different and need retuning.
#8
09/08/2010 (5:18 am)
Hi Justin,

Thanks for the tip. It's very interesting to hear that you were able to fix the sticking-objects problem. I started off using TGB before purchasing iTGB. I saw the same sticking problem in TGB but I was using an older version, so it's good to know that they fixed it. In my case I'm a bit too far along to change things so I'll continue to use my workaround for now, but I will definitely look at merging in those files from TGB at a later stage.