Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: Half-tile collisions?  (Read 5089 times)

0 Members and 1 Guest are viewing this topic.
Half-tile collisions?
« on: April 29, 2011, 07:22:43 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 44
Can someone give me some ideas or even examples of how one would go about coding collisions with tiles when only a portion of the tile blocks?

You'll see the grid shows the tile sizes, but I've circled a few tiles that Link only collides with half of it.


I'm coding this in Java, and right now I have some very primitive collisions with these special tiles. Mostly, I've coded in special circumstances. For example, with the cliff tile I have it where the tile is inherently not blocking(with no checks, Link walks over it), but then I have it where it detects that specific tile under Link, and if it finds it, makes it so Link can't go beyond the bottom half of the tile. This is extremely simple and works well for that tile since Link can only collide with it from one direction. However, with the fence post it's a lot more complicated since Link can run into it from any direction.

My method of collision detection right now is very simple -- I check for walls on the corners of Link's bounding box(which is very small in Link's Awakening, so I don't need to check a whole box since the tiles are larger than the bounding box itself), and if there is a wall, I stop Link from being able to move. If my code is needed I can post it, though right now it is VERY rough since I only started coding a day or two ago.
Logged

Xiphirx

wat
Re: Half-tile collisions?
« Reply #1 on: April 29, 2011, 07:30:23 pm »
  • Xiphirx
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3007
How do you determine where walls are? collision map?
Logged
  • For The Swarm
Re: Half-tile collisions?
« Reply #2 on: April 29, 2011, 07:42:16 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 44
How do you determine where walls are? collision map?
Each tile has a block-type definition.



Code: [Select]
0  walk
1  block
2  stairs
3  grass
4  shallowwater
5  water
6  pit
7  door
8  blockup
9  blockleft
10 blockdown
11 blockright

1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 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 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1,
1, 1, 1, 1, 1, 9, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 5, 5, 5, 5,
1, 1, 1, 1, 1,11, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 5, 5, 5, 5,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 5, 5, 5, 5,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 5, 5, 5, 5,
1, 1, 1, 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 4, 4,
1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 4, 4,
1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 4, 4,
1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
Logged

Xiphirx

wat
Re: Half-tile collisions?
« Reply #3 on: April 29, 2011, 07:45:27 pm »
  • Xiphirx
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3007
Okay, then how about adding another block type, halfblock, and you handle the collision to half of the blocks width/height instead of its width/height?
Logged
  • For The Swarm
Re: Half-tile collisions?
« Reply #4 on: April 29, 2011, 07:48:58 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 44
Okay, then how about adding another block type, halfblock, and you handle the collision to half of the blocks width/height instead of its width/height?
They're already defined -- the blockleft, blockright and such are definitions for half-blocks. But that doesn't help with the concept of interacting with only half of a tile. Like I said, the blockdown was very easy to do since you only hit it moving down. I don't have to worry about coding what happens when Link collides with it from the bottom/left/right. However, with the fence post it's problematic because I have to code special circumstances for each direction. I could probably heck up some very crude methods, but I'm hoping to come up with a more... appropriate method.

off-topic: Where would one post something like a whole tmx format of a Zelda game for others to be able to use? I made it for my little game but I wouldn't mind sharing it.
« Last Edit: April 29, 2011, 08:07:16 pm by Dusty »
Logged

Xiphirx

wat
Re: Half-tile collisions?
« Reply #5 on: April 30, 2011, 12:07:03 am »
  • Xiphirx
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3007
? don't you handle each type of collision separately already? If so, you can just do a switch on the block type, when its blockleft, for example, you compare it like normal, but using half of the width. The collision code should be the same, just that the collision box is half the size...
Logged
  • For The Swarm

Mamoruanime

@Mamoruanime
Re: Half-tile collisions?
« Reply #6 on: April 30, 2011, 01:32:16 am »
  • ^Not actually me.
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 9786
The problem is that you're treating tiles as 16x16 entities, when in the GB games they're 8x8 entities pieced together on a "block". "Half-collisions" is going to be very messy and it's going to look very shoddy in your code if you don't work out splitting up your tiles into 4 collision entities.
Logged
Re: Half-tile collisions?
« Reply #7 on: April 30, 2011, 02:52:49 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 44
The problem is that you're treating tiles as 16x16 entities, when in the GB games they're 8x8 entities pieced together on a "block". "Half-collisions" is going to be very messy and it's going to look very shoddy in your code if you don't work out splitting up your tiles into 4 collision entities.
I'll have to look up specs, even if that is so there are smaller collisions than 8x8, such as the doors. Each side of the door blocks with a 4 pixel collision.

Regardless, I've already recreated the entire overworld with 16x16 tiles, I'd rather not start over. I'd much rather just code up some crude checks or even some alternative(like creating shapes for each tile and do polygonal collision) than start over.


However, I'm pondering, and I think I've found a way to do this.
« Last Edit: April 30, 2011, 04:29:25 am by Dusty »
Logged

Xiphirx

wat
Re: Half-tile collisions?
« Reply #8 on: April 30, 2011, 04:43:48 am »
  • Xiphirx
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3007
Aren't you doing standard bounding box collision?...

Shouldn't it be as easy as

Code: [Select]
case BLOCKLEFT:

if link x < tile.x+tile.w/2 && link.y > tile.y && link.x > tile.x && link.y < tile.y+tile.h
{
collision!
}

Logged
  • For The Swarm
Re: Half-tile collisions?
« Reply #9 on: April 30, 2011, 04:54:34 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 44
Okay, the problem was I was doing checks relative to Link's position, instead of just doing the checks where I was checking for collisions. Was a very simple solution when it finally hit me:

Code: [Select]
 public boolean checkCollision(float cx,float cy) {
    if (tileType(cx,cy) == 1) return true;
    else if (tileType(cx,cy) == 8 && (cy % 1) < .5) return true;
    else if (tileType(cx,cy) == 9 && (cx % 1) < .5) return true;
    else if (tileType(cx,cy) == 10 && (cy % 1) > .5) return true;
    else if (tileType(cx,cy) == 11 && (cx % 1) > .5) return true;
    return false;
  }
« Last Edit: April 30, 2011, 04:57:56 am by Dusty »
Logged
Re: Half-tile collisions?
« Reply #10 on: May 01, 2011, 08:45:43 am »
  • Wooper Don't Give a !@#$%
  • *
  • Reputation: +16/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1457
The obvious solution is to take Mammy's advice and split it up even further. I'd do chunks of 4 blocks, 4 x 4 to make up one 16 x 16 block, and then build your map that way.

Another way to do it (Not efficient at all in this case and more effort than its worth) is to use the Separating Axis Theorem to find a vector you need to push Link out of collision each frame. This uses some math (Dot product) and is better suited to more complex collision systems, especially since it seems like the only time you'll ever need special cases like this is the sign post.

EDIT: Or it looks like you solved your own problem. Oh well. Maybe the info will help somebody else sometime.
Logged
ROLL TIDE WHAT? **** YOU!!! Geaux Tiga

~The Gaurdians of ZFGC~
Kirby, metallica48423, Max, Vash, walnut100
  • Gamers & Developers Unlimited
Re: Half-tile collisions?
« Reply #11 on: May 01, 2011, 05:08:17 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 44
The obvious solution is to take Mammy's advice and split it up even further. I'd do chunks of 4 blocks, 4 x 4 to make up one 16 x 16 block, and then build your map that way.
That is a hell of a lot of work you know O.o
Logged
Re: Half-tile collisions?
« Reply #12 on: May 02, 2011, 01:17:11 am »
  • Wooper Don't Give a !@#$%
  • *
  • Reputation: +16/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1457
^ Not compared to the alternatives. Just trust me on that.
Logged
ROLL TIDE WHAT? **** YOU!!! Geaux Tiga

~The Gaurdians of ZFGC~
Kirby, metallica48423, Max, Vash, walnut100
  • Gamers & Developers Unlimited
Re: Half-tile collisions?
« Reply #13 on: May 02, 2011, 02:13:04 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 44
^ Not compared to the alternatives. Just trust me on that.
Working with 8x8 tiles, especially when you've already mapped an entire overworld, is a lot more work than working with 16x16 tiles. 4x4 tiles is A HELL of a lot more effort involved with mapping. You end up having to fill 16x more space. Honestly, making an alternative(mines was very simple, and very effective) wouldn't but that hard. If I needed to I could have looped over the tile data when Link entered an area and created a polygon bounding box for each tile and did polygonal collision checks if I really needed to.
Logged
Re: Half-tile collisions?
« Reply #14 on: May 02, 2011, 05:09:23 am »
  • Wooper Don't Give a !@#$%
  • *
  • Reputation: +16/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1457
Actually I was more referring to reworking your map to smaller units is much less work than getting buried knee deep in linear algebra

Collision checks are easy. Resolving them aren't. Its much easier to say "You can't move onto this space" then it is to say "if you move onto this space you have to move x units in this direction and I derived that number by projecting the axes onto a one dimensional plane and then gathering data from those results"

It could be easiest to write a heck for specific tiles but to me it seems like the grunt labor of putting a smaller unit map in place is the easiest option

But you're gonna do what you're gonna do I'm just trying to help you better understand your options :P
Logged
ROLL TIDE WHAT? **** YOU!!! Geaux Tiga

~The Gaurdians of ZFGC~
Kirby, metallica48423, Max, Vash, walnut100
  • Gamers & Developers Unlimited

Mamoruanime

@Mamoruanime
Re: Half-tile collisions?
« Reply #15 on: May 02, 2011, 02:30:41 pm »
  • ^Not actually me.
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 9786
Well you don't really even need to work with 8x8 tiles... That wasn't exactly what I was getting at. Most any game made has to have some form of definition to it's collisions. You can still do a sort of tile-based collisions for this, you just need to make your tile images 16x16, and place collision entities on an array supporting 8x8 or 4x4 sized collision entities.

Lets say your tile is the 8th index on the tileset, and that particular tile has a small 8x8 spot in the corner that's supposed to be solid, then you'd have it check for whatever collision data is there for the 8th tile index.
Code: [Select]
tile|col
8 -- 10
     00


^So tile 8 has an even smaller set of collision data. You then compare Link's position with the collision data array instead of the tile array.
Logged
Re: Half-tile collisions?
« Reply #16 on: May 04, 2011, 05:17:05 am »
  • Wooper Don't Give a !@#$%
  • *
  • Reputation: +16/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1457
^ I kinda assumed that he got the concept of splitting the map into collisions and art, which I shouldn't have, good catch

I can't think of a good reason to not split it up into smaller chunks tight butthole
Logged
ROLL TIDE WHAT? **** YOU!!! Geaux Tiga

~The Gaurdians of ZFGC~
Kirby, metallica48423, Max, Vash, walnut100
  • Gamers & Developers Unlimited
Re: Half-tile collisions?
« Reply #17 on: May 04, 2011, 07:13:41 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 44
^ I kinda assumed that he got the concept of splitting the map into collisions and art, which I shouldn't have, good catch

I can't think of a good reason to not split it up into smaller chunks tight butthole
It's a lot more effort to create a map using smaller tiles, and in this case, with very little payoff.
Logged
Re: Half-tile collisions?
« Reply #18 on: May 04, 2011, 11:14:02 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 2245
^ I kinda assumed that he got the concept of splitting the map into collisions and art, which I shouldn't have, good catch

I can't think of a good reason to not split it up into smaller chunks tight butthole
It's a lot more effort to create a map using smaller tiles, and in this case, with very little payoff.
I believe he's referring to the collision size, not the actual tile size, you would still be placing 16x16 tiles. you would just be defining the collisions for that tile on a smaller scale which you will have predefined.
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.277 seconds with 76 queries.

anything