Game Development Community

Need help whit on collision movement.

by Christer Landstedt · in Torque Game Builder · 02/06/2009 (5:41 am) · 2 replies

Hi I am very new to TGB and I need some help please. I am making a Sokoban or Lolo like game and I can’t figure out how to make the crates move when the player push them. Any help some one could give me would be greatly appreciated.

#1
02/06/2009 (9:04 am)
Ok (after a quick google on those games),
It looks like those are tile based games, that makes things simpler.

So when a block is hit you could check to see what tile it is currently in and then what tile the hittee is in, that would give you the direction to move, and then a quick check to see that the target tile is empty, and if it is, issue a move for the block to the empty tile. Even if you don't actually use a tileMap you can just keep a 2 dimensional array running with the positions of the blocks.

Or if you don't want your game to be tile based you could try letting the physics engine let objects send and receive physics collisions and see if that will work for you.

#2
02/12/2009 (7:56 am)
Hi thanks for the tip. I am using tiles somewhat but only for the level. The object I have chosen to place freely sins I don’t know a lot about TGB yet. So any way I have been trying to do as you said whit collision and detecting from were the box get the collision but I have not succeed. The thing is I kind of know what to do and somewhat how to do it but sins I am still to new to TGB it is really hard for me to figure out how to do it.
Any way this is what I have come up whit so far and it is not working I have tried many different things and code structures but nothing really seems to work and that have a lot to do whit my inability to understand how to get onCollision code to work. If some one could be so kind as to point me in the right direction or give me any help I would be really happy.

function boxClass::onCollision($player)
{  
   // collides with player to the left
   if (%normalX == 1 && %normalY == 0)
   {
		%this.setLinearVelocityX(100);
		return;
   }
   
   // collides with player to the right
   if (%normalX == -1 && %normalY == 0)
   {
		%this.setLinearVelocityX(-100);
		return;
   }
   
   // collides with player from below
   if (%normalX == 0 && %normalY == -1)
   {
		%this.setLinearVelocityY(-100);
		return;
   }
   
   // collides with player from abow
   if (%normalX == 0 && %normalY == 1)
   {
		%this.setLinearVelocityY(100);
		return;
   }
}