Game Development Community

Object to Object to Tilemap Collision

by John Sripan · in Torque Game Builder · 02/27/2006 (6:26 pm) · 6 replies

I'm trying to set up a simple game where an avatar can push blocks around a side scrolling platformer area. The problem is that I am able to push non-player objects through the tilemap using the player. In addition, I would like the player to be able to walk on the non-player objects, but when he tries to jump on them he pushes them out of the way. How should I solve this?

--john

About the author

Recent Threads


#1
02/27/2006 (10:40 pm)
On the second part, you may try modifying the collision response based on the %normal returned--if the collision is mostly from the side then you would push the object, but if mostly from the top (they jumped on top of it), then it would be treated the same as walking on a tile.

Not trivial, and certainly not the only way, but the first thought that jumped out at me.

The first part I'm not sure...hopefully Melv will catch this sometime soon, or someone else that has given something like this a shot!
#2
02/28/2006 (12:53 am)
Another way to solve the second problem if the objects only move in a single axis (i.e. left to right) would be to set the world limit tightly to them in the vertical direction (i.e. the world limit is from there top to there bottom if you want left to right movement).
#3
02/28/2006 (6:13 pm)
I would do the following:

* Assign the player, enemies, non-movable blocks and moveable blocks on different layers and in different groups.

* Set the player, enemies and moveable blocks to send and recieve collisions and the non-moveable blocks to just send collisions

* Create two functions, one to handle the player colliding with the moveable block and one to handle the enemy colliding with the moveable block. If you want your moveable blocks to be affected by gravity you'll need an additional one to handle the moveable block colliding with the tile map.

* With the function that handles player collisions with the moveable block I would think it work something like this:

If the player is higher than the object ( use getPositionY() )
If the player's Y velocity is moving down
Cast a collision downwards to see if the block can move down
If it can move the block down
If it can't 0 the player's Y movement
Else 0 the player's Y velocity
If the player is on the side of the object ( use getPositionX() )
If the player is moving left
Cast a collision left to see if the block can move left
If it can move left
If it can't stop the player from moving
If the player is moving right
Cast a collision right to see if the block can move right
If it can move right
If it can't stop the player from moving

Thats how I would structure it without seeing any of your code.

Hope this helps.
#4
03/01/2006 (6:44 am)
That writeup sounds pretty solid to me as well.
#5
03/02/2006 (10:22 pm)
The problem I'm having now is that when I castCollsion in any direction while the player is in contact with the object, it will return the player's collision since the player is considered first to collide with it. In addition, since I have gravity set up as constantForce, zeroing the linear velocity only slows down the player, it doesn't stop him, since the force will get applied on update.

--john
#6
03/04/2006 (8:25 am)
CastCollision actually returns all of the objects that are predicted to collide with over the time interval you provide...you just need to scan out the list in full to get all of the collisions.

Also, the best technique for castCollision is to make sure that you:

--save off the current movement params using getLinearVelocity, getPolarVelocity, etc.
--force set the params that you want to be checked for, such as setLinearVelocityX/Y, etc.
--cast your collision
--reset the physics from the saved off data

I used this technique to determine (in a platformer game) if the player was in fact flying (not in contact with any tiles) by:

--saving his current position, velocities, and forces
--giving the player a negative Y velocity (small, but not trivial)
--casting a collision for .1 sec
--resetting params to current state
--seeing if the returned collision cast list was empty

If this returned a tilemap collision, then I could assume that the player was in fact touching (or very very soon will be touching) a tile beneath him, and therefore I should use ground contact movement calculations instead of flying movement calculations.