Game Development Community

Collision problem

by Drethon · in Torque Game Builder · 09/14/2012 (8:23 pm) · 1 replies

I'm playing with the following code in the platformer tutorial to make movement have an acceleration and deceleration that differs between being on ground and airborne. If I put the commented out code back (basically forcing sped to velocity of 30) in a collision is detected, if I leave it commented out the collision is not detected.

Any help?

%this.againstLeftWall = false;
         %xVelocity = %this.getLinearVelocityX() ;

         if ( mAbs ( 30 - %xVelocity ) < 2.0 )
         {
            %this.setConstantForceX ( 0 ) ;
            %this.setLinearVelocityX ( 30 ) ;  
         }
         else
         {
            if ( %this.airborne == true )
            {
               %this.setConstantForceX(5);
            }
            else
            {
               %this.setConstantForceX(50);
            }
         }
         //%this.setLinearVelocityX ( 30 ) ;

#1
09/14/2012 (8:52 pm)
Ah I figured it out. The collisions were being detected by a periodic function rather than a callback. This meant that if the object isn't constantly trying to hit the wall, the periodic function will miss the collision. Looks like I'll be learning to use callbacks...