Game Development Community

1.5 differing collision on instances of the same object

by Conor O Kane · in Torque Game Builder · 07/15/2007 (1:42 am) · 4 replies

I'm finding the collision circle on my bullets changes with each bullet.

Here's a screenshot of the game where the collision is working correctly:

www.cokane.com/temp/collision_bug02.jpg

and here's a screenshot of the same game a few seconds later and things are going wrong:

www.cokane.com/temp/collision_bug01.jpg

Here's the code I'm using to generate the bullets:

function playerBullet::fire(%this, %position, %color)
{
	// initialize and fire the bullet
   %this.setPosition(%position);
	%this.setWorldLimit(kill, "-655 -377 655 377", true);
   %this.setAnimation(anim_bullet02Animation);
   %this.setSize(64, 16);
	%this.setCollisionActive( true, false );
   %this.setCollisionPhysics(false, false);
   %this.setCollisionCallback(true);
	%this.setCollisionDetection(circle);
	%this.setCollisionCircleScale(0.5);
	
	if ($debugOn) %this.setDebugOn(5);
	
	// initialize and attach the glow
	if (%color $= "orange")
		%this.glow.setImageMap(bulletGlowOrangeImageMap);
	else if (%color $= "blue")
		%this.glow.setImageMap(bulletGlowBlueImageMap);
	%this.color = %color;
	%this.glow.setSize(64, 32);
	%this.glow.mount(%this);
	%this.glow.setDstBlendFactor(one);
	
	%this.setLinearVelocityX(%this.bulletSpeed);
}

I can't work out what could be causing this, and it didn't happen with version 1.1.3.

and why don't img tags work on the forum???

#1
07/19/2007 (9:44 pm)
I take it nobody else is experiencing this? Is anybody making a fast-paced game with TGB 1.5?
#2
07/21/2007 (12:52 am)
Hey, I was experiencing the same thing.. and it freaked me out. I'm making a fast-paced game for the shmup competition also ;)
anyway, with the collision, I've come to believe that it's working correctly. If you're creating the explosion sprite on collision, or after collision, you need to use the position for the newly created object from %contacts (in the OnCollision method). That will give you the proper location.

for example, here is part of the code in my t2dSceneObject::onCollision( %srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts )

case ($GAME::PLAYERBULLET_GROUP): //player bullet
            switch ( %dstObj.getGraphGroup() )
            {
               case ($GAME::ENEMY_GROUP):
                  %srcObj.explode(%contacts,0);
               case ($GAME::OBSTACLE_GROUP):
                  %srcObj.explode(%contacts,0);
               case ($GAME::BULLET_GROUP):
                  if ( %dstObj.cancelling )
                  {
                     //%srcObj.setAtRest();
                     //%srcObj.safeDelete();
                     //%dstObj.gotoPool(bulletPool);
                  }


the %srcObj.explode(%contacts,0); is doing this:

function bulletClass::explode( %this, %position, %hide )
{
   if (isObject(%this.explodeEffect))
   {
      if ( !%hide )
      {
         %explosion = %this.explodeEffect.cloneWithBehaviors();
         %explosion.position = %position;
         %explosion.setEffectLifeMode("Kill", 1.0);
         %explosion.playEffect();
      }
   }
   %this.safeDelete();
}

that's just cloning a particle effect (in your case I think you have a sprite and a particle effect?) and it sets its position to what I passed from %contacts

I may not have explained clearly, but hopefully it helps!
#3
07/21/2007 (1:23 am)
Also, if you have a situation where you notice the bullet or any fast moving object disappearing before hitting the object, you can make it look better by scheduling the safeDelete() a bit further into the future, and turning off collisions on the bullet. It might also help if the collision response is set to STICKY, since it will move the object to the point of collision.

%srcObj.setCollisionActive( 0, 0);
%srcObj.schedule(100,"safeDelete");

You could also just make the bullet play a destroy animation and allow it to continue along its trajectory with the collision turned off and scheduled to delete soon... (without STICKY collision response), this might look similar to some shooters, where the bullet fragments but stays moving at the same speed over the ship it's colliding with.
#4
07/21/2007 (4:33 am)
Thanks for the tips Ezra - I'll try those out, and good luck with the contest!