RC3: onCollision Multiple %points Not Working
by Jim Taylor · in Torque Game Builder · 06/17/2006 (8:32 pm) · 1 replies
I don't know if this has been reported elsewhere but when I use the onCollision callback and attempt to read vectors of multiple collision points as returned in the %points argument they don't return the correct values.
It seems that one of the vectors is returned correctly but the second vector is always just approx 1.5 ~ 4.5 x-axis units larger regardless of where the second collision point is actually placed (the y-axis values appear to be correct).
The bug (if it is one) should be reproducible if an object with a collision poly that has 2 contact points on the bottom falls onto a tile platform and then echo the resultant %contactCount and %points to the console.
I don't know if it matters but the imagemap I am using is pretty big and the collision poly for this object is probably about 20% of the whole screen.
I hope it's not just me being dumb because I've been trying to get this to work for hours.
-Jim.
It seems that one of the vectors is returned correctly but the second vector is always just approx 1.5 ~ 4.5 x-axis units larger regardless of where the second collision point is actually placed (the y-axis values appear to be correct).
The bug (if it is one) should be reproducible if an object with a collision poly that has 2 contact points on the bottom falls onto a tile platform and then echo the resultant %contactCount and %points to the console.
I don't know if it matters but the imagemap I am using is pretty big and the collision poly for this object is probably about 20% of the whole screen.
I hope it's not just me being dumb because I've been trying to get this to work for hours.
-Jim.
Torque Owner Jim Taylor
This is hard to describe without a diagram but imagine a large source object with two collision points on the bottom falling onto a platform constructed of 6 tiles which all have collision polys. The true collision points from the source object are on the first (left) tile and on the far right (last) tile. All four tiles in between will also report collisions.
The engine will first calculate the source collision points (max = 2) and all is well with the world. Then it comes to handle the destination collisions and starts with the first tile on the left of the platform. Because this tile has a true collision point it is able to determine that point and then attempts to calculate a second collision point (because the collision point count from the source calculation is at 2). Because the second true collision point is on a different tile to the right of its (maximum) right edge it sets the second collision point to its right edge position and therefore returns two collisions the second being as close to the true collision as it can get...its right side edge.
The next tile is then processed and because it does not have a true collision point on it, it returns both its extreme left side edge position and its extreme right side edge position as the two contact points. This is the same for the remaining 3 center tiles until it comes to process the last (right hand) tile which does have the other true contact point.
At this point the collision handler returns the true collision point but (still looking for 2 collision points) it sets the second collision point to its extreme left edge, being as close as it can get to the other true collision point.
This wouldn't necessarily be a problem provided that the onCollision call back returned the source contact points (which are still the correct true contact points) but this is not the case.
In a section of the t2dPhysics.cc code labeled "// Projected Segment." It determines that if the source contact point minimum coordinate is less than the destination contact point minimum then it sets the source contact points equal to the destination contact points so that when the function returns, the source contact points are equal to the last tile contact points that it detected.
I hope that this is making some sense. At this point I was able to get the onCollision callback to return the true source contact points by commenting out line 2047 of the t2dPhysics.cc file and rebuilding the project.
It seems to be working well at the moment I just hope I haven't broken some other functionality. Any feedback on this would be great if anyone can figure out what I'm talking about.
-Jim.