Jump to content

  • Log In with Google      Sign In   
  • Create Account

Different sides to a square tile

  • You cannot reply to this topic
2 replies to this topic

#1 Truerror   Members   -  Reputation: 454

Like
0Likes
Like

Posted 04 September 2014 - 06:23 PM

The team I'm in is currently making a 2D platformer game, and we've decided to use Unity for it. Like many other 2D platformers, the patforms themselves will be made from square tiles. However, the action is different if the player character collides with a tile from the side (touching a 'wall') rather than colliding with that same tile from the top (touching a 'floor').

 

I was thinking about having having separate subobjects for each side, with each subobject having its own edge collider. That way, I could tell the difference between the sides and the top. The designer of the game wanted the game to be based on parkour, so we might have actions like wall climbing and such.

 

There are two other options I'm considering. The first is to have 3 raycasts on each side of the player character (except the top). Thus if the side raycast(s) hit a tile, then the actions done are wall actions (climbing or hanging) and if the bottom raycast hits a tile  the actions done are floor actions (standing idle, running, etc.). The other option is similar in concept, but with subobjects instead of raycasts.

 

Which one do you think would be best, considering Unity's collision support? Or do you have any other ideas?



Sponsor:

#2 Buckeye   Crossbones+   -  Reputation: 4918

Like
0Likes
Like

Posted 04 September 2014 - 07:30 PM

For what you describe, raycasting seems overkill. Can you simply note the position and velocity of the player, and, perhaps using a quadtree or similar, look up the nearest tile(s) of interest, and make appropriate decisions from that information?

 

Casting rays as you describe, unless you decide on inviable rules for and very carefully design tile locations, will eventually give you problems - e.g., a player is falling at an angle, and "collides" with the corner of a tile. Just before he "hits" the tile, the raycasts result in no hits. The next instant, when the character just "overlaps" the corner, the "down" raycast hits the top of the tile, and the "side" raycast hits the side of the tile; or worse - results in no hits.

 

By the way, the solution to that is not to increase the number of raycasts; e.g., to add "diagonal" raycasts in four directions. Someone will design a level that has a "gotcha!"


Edited by Buckeye, 04 September 2014 - 07:30 PM.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.


#3 Truerror   Members   -  Reputation: 454

Like
0Likes
Like

Posted 04 September 2014 - 08:19 PM

For what you describe, raycasting seems overkill. Can you simply note the position and velocity of the player, and, perhaps using a quadtree or similar, look up the nearest tile(s) of interest, and make appropriate decisions from that information?

 

Casting rays as you describe, unless you decide on inviable rules for and very carefully design tile locations, will eventually give you problems - e.g., a player is falling at an angle, and "collides" with the corner of a tile. Just before he "hits" the tile, the raycasts result in no hits. The next instant, when the character just "overlaps" the corner, the "down" raycast hits the top of the tile, and the "side" raycast hits the side of the tile; or worse - results in no hits.

 

By the way, the solution to that is not to increase the number of raycasts; e.g., to add "diagonal" raycasts in four directions. Someone will design a level that has a "gotcha!"

 

That's a valid concern. Yes, there is a possibility that the PC collides with a tile, but the raycast doesn't. So I guess that leaves only the first and the third option open.

 

Btw, just in case someone is wondering, I'm not looking for a way to handle basic collisions (Unity's physics system is good enough for that, so objects won't simply move through other objects and such), what I'm looking for is a way for the player character to tell which side of a square tile is it colliding with.







PARTNERS