Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (480)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (546)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Collisions that aren't AABB  (Read 2106 times)
0 Members and 1 Guest are viewing this topic.
Offline Mads

JGO Ninja


Medals: 26
Projects: 3
Exp: 6 years


One for all!


« Posted 2012-07-25 20:33:38 »

I know how to do a proper sidescroller like the old Mario, where the collisions are just AABB. It's pretty easy.

Now I want to do something different, and have a terrain that's not boring. How would I go about making my character walk on a slope, for instance? I bet there's tons of material on this, but google-fu only returned a low-quality actionscript-riddled solution that's just not feasible in the long run.

Thanks in advance. Smiley  

EDIT: I posted this on the wrong board  Sad Sorry! Meant to post in "Newbie questions".

Offline Cero
« Reply #1 - Posted 2012-07-25 20:45:56 »

I know how to do a proper sidescroller like the old Mario, where the collisions are just AABB. It's pretty easy.

Now I want to do something different, and have a terrain that's not boring. How would I go about making my character walk on a slope, for instance? I bet there's tons of material on this, but google-fu only returned a low-quality actionscript-riddled solution that's just not feasible in the long run.

Thanks in advance. Smiley  

EDIT: I posted this on the wrong board  Sad Sorry! Meant to post in "Newbie questions".

really really depends on how you do it
every part of the slope can be a triangle; then do rectangle triangle collision detection. or just line intersection...
the could also be internally boxes and push you up or down a certain amount...

Offline Mads

JGO Ninja


Medals: 26
Projects: 3
Exp: 6 years


One for all!


« Reply #2 - Posted 2012-07-25 20:52:56 »

every part of the slope can be a triangle; then do rectangle triangle collision detection. or just line intersection...
the could also be internally boxes and push you up or down a certain amount...

I know how to detect a collision. I'd like to be able to push my character along it, though. I'd rather not have a million small boxes Roll Eyes

I think what I need is a way to pull where on the y-axis my character is, if he's on x10 on a slope going from (0,0) to (30, 30). I still wouldn't know how to push him along when walking though  Cranky

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Damocles
« Reply #3 - Posted 2012-07-25 21:51:23 »

well, if the endpoint of the x-movement is inside the triangle, and the triangle has a 45degree slope,
the endposition is the hight of the triangle at this point.

Lets say its a slope going upward to the right, and you move right.
First check if the endpoint of the character is on the tile with such a slope.
If yes, check at wich % point of the tile he ends up.
Then do an interpolation how high it is there.

-> if the char is moving right, you need to check this for the lower right point of your collision box...
Or check it for both sides, and apply the highest hight.

(if the tile is 1 wide, and the endpoint is at 0.8, then the hight after pushing would be also 0.8 higher than the bottomline of the tile)
For a 45/2 degree slope (over 2 tiles), it would be 0.4 high.

Cant pull out some example code now. But it should be easy to develop it from here.

Just look at all the side conditions:

if the endtile is "full", but the char is currently on a slope, the char will end up on TOP of the end-tile.
If there is no slope, he would collide already with the edge of the tile.

Offline Cero
« Reply #4 - Posted 2012-07-25 22:59:54 »

its easy to code per se, but hard to get really right, without wasting too much performance with pixel iterations
especially with jumping, landing, running down and up - all cases have to work

Offline UprightPath
« Reply #5 - Posted 2012-07-25 23:40:32 »

You can easily do slopes that are AABB based!

I mean everything in my platformer is based off of that. It just takes a little bit more finesse.

Offline Mads

JGO Ninja


Medals: 26
Projects: 3
Exp: 6 years


One for all!


« Reply #6 - Posted 2012-07-26 19:09:31 »

You can easily do slopes that are AABB based!

I mean everything in my platformer is based off of that. It just takes a little bit more finesse.

Could you perhaps elaborate on that?

Offline UprightPath
« Reply #7 - Posted 2012-07-26 19:25:10 »

Well, let's say you have a tile. This tile will have information about the 'relative' heights across the entire tile based on the 'size' of the tile.
1  
2  
3  
4  
5  
6  
7  
public class Tile {
    public float angle;
    public int[] heights;
    public int getOffset(int offset) {
        return heights[offset];
    }
}

Then you have your Entity, it's standing a x and y.
1  
2  
3  
4  
5  
6  
7  
8  
    int tileX = x / tileSize;
    int offsetX = x % tileSize;
    int tileY = y / tileSize;
    int offsetY = y % tileSize;
    Tile tile = getTile(tileX, tileY);
    entity.setY(tile.getOffset(offsetX));
    entity.setSpeedX(Math.applicableTrigFunction(tile.getAngle()) * someConstant);
    entity.setSpeedY(Math.applicableTrigFunction(tile.getAngle()) * someConstant);

This is a 'basic' method for doing it. If you really want a chunk of source code that manages this, I can probably make one of the older iterations of my platformer's code available. It uses this method (Well, a fancier version that finds the highest point between the character's left edge and right') . Basically, it allows you to turn your tiles into semi-height maps.

Offline Roquen
« Reply #8 - Posted 2012-07-26 19:26:13 »

More generally, like quadtrees & uniform grids, the primary role of aligned or oriented boxes (tree based or individual) is to provide a quick rejection prior to performing the "complex" intersection, collision, whatever-else check.
Offline Mads

JGO Ninja


Medals: 26
Projects: 3
Exp: 6 years


One for all!


« Reply #9 - Posted 2012-07-26 19:35:00 »

Well, let's say you have a tile. This tile will have information about the 'relative' heights across the entire tile based on the 'size' of the tile.

I see, thank you very much! That helped a lot.

More generally, like quadtrees & uniform grids, the primary role of aligned or oriented boxes (tree based or individual) is to provide a quick rejection prior to performing the "complex" intersection, collision, whatever-else check.

You're right, I should stop thinking in the box so much. Smiley


Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Ultroman

JGO Knight


Medals: 24
Projects: 1


Snappin' at snizzes since '83


« Reply #10 - Posted 2012-07-27 05:21:31 »

I did a little project and wrote up the way I did it here. I made it so a tile just has a point in each side, and use the line between them to find the Y. It works very well.
Looking at the suggestions here, though, it seems easier to code a collision-system using tiles that have an array of Y-positions for each X, but that also means you have to manually design each tile with different Y positions. Unless you in some clever way generate it by finding the highest point for each X that isn't transparent in the tile image.

- Jonas
Offline UprightPath
« Reply #11 - Posted 2012-07-27 06:24:19 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
public enum TileType {
// Have a bunch of different tile collision arch types here! Make them enums to be accessed easily. :3 Or, however you want to, but it's important that they're singleton access.

private int max;
private int[] height = new int[32];

public int getFromLeft(int offsetX) {
    int max = 0;
    for(int i = offsetX; i < 32; i++) {
        max = Math.max(heightTop[i], max);
    }
    return max;
}

public int getFromRight(int offsetX) {
    int max = 0;
    for(int i = 0; i < offsetX + 1; i++) {
        max = Math.max(heightTop[i], max);
    }
    return max;
}

public int getMax() {
    return max;
}

}


From there, you can manually declare each TileType's Ys and access them quickly. For certain things, it's fairly easy to come up with the height formulas. I mean it's just rise-over-run for the most part. But, it also allows you to have stair based collisions (So that your character will actually 'stand' on the flat portions of stairs, instead of following an incline up them) as well as arbitrarily designed tile configurations. This is important if you want to have relatively large tiles.

Offline Mads

JGO Ninja


Medals: 26
Projects: 3
Exp: 6 years


One for all!


« Reply #12 - Posted 2012-07-27 13:10:52 »

I have decided that I'd rather go with tiles. I want to then define only the two top-vertices, and from that I can derive the slope. Then it's just basic line math. Bim bam boom!

I figured I could do it upside down for a roof.

Thanks guys. Cheers!

Offline Roquen
« Reply #13 - Posted 2012-07-27 13:13:33 »

Generalized line equation is your friend.
Offline Mads

JGO Ninja


Medals: 26
Projects: 3
Exp: 6 years


One for all!


« Reply #14 - Posted 2012-07-27 13:15:11 »

Generalized line equation is your friend.

True Smiley I think I'll wait a bit with this, though:
Click to Play

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

atombrot (20 views)
2014-08-19 09:29:53

Tekkerue (21 views)
2014-08-16 06:45:27

Tekkerue (21 views)
2014-08-16 06:22:17

Tekkerue (12 views)
2014-08-16 06:20:21

Tekkerue (19 views)
2014-08-16 06:12:11

Rayexar (55 views)
2014-08-11 02:49:23

BurntPizza (37 views)
2014-08-09 21:09:32

BurntPizza (27 views)
2014-08-08 02:01:56

Norakomi (35 views)
2014-08-06 19:49:38

BurntPizza (64 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!