Game Development Community

TDN Platformer Collsions, please advise

by wingman · in Torque Game Builder · 08/11/2008 (3:13 pm) · 4 replies

I finally got around to checking out TGB since Ive owned it for awhile...I jumped on the TDN to go through the ninja platformer, and have spent several hours messing around with all kinds of stuff. The only problem Im having is the collision between the ninja and the platforms. Ive followed the tutorial EXACTLY. Im using scene objects mapped around tile objects for collision boxes just like the tutorial. But when the ninja falls or jumps onto some of the scene objects, he is very glitchy (like the stand animation and run animation are trying to play at the same time, like something in script is not firing off the correct collision checks). On some scene objects the ninja doesnt do this, its weird. Just wondering if this is a known issue or if anyone has a suggestion before I start breaking stuff that doesnt need breaking. tia

#1
08/11/2008 (3:20 pm)
There are a TON of posts around the forums concerning problems and fixes with that tutorial. I don't personally know anything about it though...
#2
08/11/2008 (8:19 pm)
COLLISION: 1319 -0.408602 -42.000000 32.432602 -0.000000 -1.000000
NORMAL X: -0.000000
NORMAL Y: -1.000000
COLLISION: 
NORMAL X: 
NORMAL Y: 
COLLISION: 1319 -0.408602 -42.000000 32.432602 -0.000000 -1.000000
NORMAL X: -0.000000
NORMAL Y: -1.000000
COLLISION: 
NORMAL X: 
NORMAL Y: 
COLLISION: 1319 -0.408602 -42.000000 32.432602 -0.000000 -1.000000
NORMAL X: -0.000000
NORMAL Y: -1.000000
COLLISION: 
NORMAL X: 
NORMAL Y: 
COLLISION: 1319 -0.408602 -42.000000 32.432602 -0.000000 -1.000000
NORMAL X: -0.000000
NORMAL Y: -1.000000
COLLISION: 
NORMAL X: 
NORMAL Y: 
COLLISION: 1319 -0.408602 -42.000000 32.432602 -0.000000 -1.000000
NORMAL X: -0.000000
NORMAL Y: -1.000000
COLLISION: 
NORMAL X: 
NORMAL Y: 
COLLISION: 1319 -0.408602 -42.000000 32.432602 -0.000000 -1.000000
NORMAL X: -0.000000
NORMAL Y: -1.000000

The above is a snippet from my console.log file. Below is a snippet from the playerClass.cs file with my echoes thrown in:
...
function playerClass::updateVertical(%this)
{
   %yVelocity = %this.getLinearVelocityY();
   
   %this.setLinearVelocityY(10);
   %collision = %this.castCollision(0.005);
   
   %normalX = getWord(%collision, 4);
   %normalY = getWord(%collision, 5);

// bug:  it shows a collision and x/y then nothing repeatedly
echo("COLLISION: " @ %collision);
echo("NORMAL X: " @ %normalX);
echo("NORMAL Y: " @ %normalY);

   // no collision
   if (%collision $= "")
   {
      %this.airborne = true;
      %this.setConstantForceY(100);
      %this.setLinearVelocityY(%yVelocity);
      return;
   }
...

As you can see, the updateVertical function is constantly reading a collision, no collision, collision, no collision....

I only have the floor scene object to collide with. I can jump up and down on it, and every other jump it will glitch up. When it DOES NOT glitch, I can check the console and look at my echoes and they are never null, but when it does glitch, the console is reading null data every other pass through the function.

This is causing the player animation to switch rapidly from one animation to the next (its switching between the playerStandAnimation and playerJumpDownAnimation every 32 ms). I havent been able to track down the cause so far. Id be surprised if I was the only one with this problem, I know others have had to try out the ninja tutorial on TDN and I even saw a youtube video of it and didnt see the above problem.

Help anybody? Is castCollision() bugged?
#3
08/12/2008 (6:48 am)
Okay, changing
%this.setLinearVelocityY(10);   
   %collision = %this.castCollision(0.005);
to this
%this.setLinearVelocityY(5);   
   %collision = %this.castCollision(0.005);
fixed the problem. Im assuming that the linear velocity being set at 10 was causing false no-collisions with castCollision because of the scaling of collision polys? Setting it to 5 fixed the problem. What do you guys think?
#4
04/30/2009 (7:47 am)
This is a good fix. I updated the TDN.