Game Development Community

Projectiles and tilemap collisions? and bestpractice states...

by Shane · in Torque Game Builder · 04/02/2007 (7:02 pm) · 1 replies

As I dig deeper into torque there are a few things I am curious about.

I have the ninja platformer demo running with some code from the scroller demo for a nice little ninja throwing effect (using the player missile code mostly). This is great, but the projectiles do not collide with the tilemap. I thought it would be a matter of setting the right collision layers, but there seems to be more code I am not handling. I realize I am not sure how the tilemap and player itself are colliding (it seems "built in" in some way through the physics system)....I would like my projectiles to collide with the tilemap and dissappear.

Then the other issue I was curious about was best practices for states. I notice the animation system seems to do a good job of handling various animation states and if that could be a reliable way to keep track of states.

What got me curious about this was realizing I had no clue (currently) how I would go about the following situation:

Suppose a player gets hit by a bad guy...
I want the player to have this recoil like animation (of getting hit) and then his chacter hop back some as it takes damage...very old school platformer like.

How would one do this? I was thinking I would create the recoil aniamtion, and upon a collision set the system to play that animation and while its playing no other "hits" can occur, and during it playing set the x,y accordingly to move the sprite in a recoil like arc (say testing for that particular animation state in update movement and updating the x, y accordingly, or once getting hit setting the x, y up accordingly along with the animation state to have the sprite jump up and back). Then once its down playing, the state is back to the idle or run states.... wasn't sure if this was a proper way of doing it and wanted some other ideas. This also begs the question, every time an enemy touches a player I have to find out what side it was from somehow (just testing perhaps x values?) and make the player recoil the opposite way... is my thinking correct here?

Thanks for any suggestions here...this will really get me started twards my first complete "tech" demo to show off to my dev team.

#1
08/12/2012 (6:14 am)
So I can't get my projectiles to collide with the tilemap either and this is the only thread that even remotely covers this topic.

The only way projectiles will touch my tile map is if I turn physics on, but then they just hit it and stop, and then start cluttering up the screen.

How do you get the tilemap to use the projectile's callback?

function fireball::fire(%this)
{
   %this.playAnimation(EmberAnimation);
   %this.setSize(25, 25);
   %this.setLayer(11);
   %this.setCollisionActive( true, true );
   %this.setCollisionPhysics(false, false);
   %this.setCollisionCallback(true);

function fireball::onCollision( %srcObj, %dstObj, %srcRef, %dstRef, %time, 
   %normal, %contactCount, %contacts )
{
   if(%dstObj.class $= "playerClass") 
   {
      %srcObj.explode();
      %dstObj.explode();
   }
}

I tried doing an "if not playerclass" line that explodes the %srcObj but that breaks the ability to fire projectiles for some reason....