Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (777)
Games in Android Showcase (231)
games submitted by our members
Games in WIP (856)
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  
  2D side scroller platformer - detecting collisions with big movement intervals  (Read 4133 times)
0 Members and 1 Guest are viewing this topic.
Offline Porlus

Junior Devvie

« Posted 2014-11-11 21:20:23 »

Hi all,
I'm making a 2D side scrolling platformer, where the platforms are effectively a 2D array of tiles rendered in much the same way as a standard 2D top-down game (0, 0) top left hand corner to (mapWidth * tileWidth, mapHeight * tileHeight) which is the bottom right hand corner. The player can land on tiles, depending on whether they're set in the array, or walk into them, or bang their head on them, etc.

Gravity is acting on the player, so if they aren't standing on a tile, they'll keep falling faster, until they reach the end of the tile map, then they'll fall forever. Everything's going fine, but I'm determining collisions much in the same way as I've been doing in the top down games, whereby I divide the player's position + delta movement, divide each of the player's surrounding corners by the tileWidth and tileHeight, then loop through them, checking if they're passable and if one isn't, I stop the player from moving in that axis.

That's all fine for those games because the player doesn't move by a significant amount at a time, but obviously when gravity's introduced the player begins to clip through tiles, because the tile features between the player's position and the player's position + delta movement.

Are there any standard methods of solving this problem as at the moment, when the player's falling more than, say, 50 blocks, they can clip straight through entire platforms.

If anyone could give me any tips on this I'd appreciate it.
Offline ags1

JGO Kernel

Medals: 367
Projects: 7

Make code not war!

« Reply #1 - Posted 2014-11-11 23:10:28 »

When the delta is greater than block size, test for collisions along the path in half-block steps.

Offline Porlus

Junior Devvie

« Reply #2 - Posted 2014-11-12 00:00:13 »

Hiya, thanks for the reply. Smiley Sounds good. I'll have a play around with it. Cheers!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline HeroesGraveDev

JGO Kernel

Medals: 382
Projects: 11
Exp: 4 years

┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻

« Reply #3 - Posted 2014-11-12 00:34:32 »

Having a terminal velocity could help avoid the problem in the first place rather than solving it.

Although if you want the player to move at insanely fast speeds it won't do.

Offline Porlus

Junior Devvie

« Reply #4 - Posted 2014-11-12 18:16:38 »

Yeah, that's a good point. I probably should have set one. Tongue It's not crucial that entities move that fast. Ah well, maybe I'll set one for the hell of it.

Anyway, got this all working now. Cheers for your help guys!
Pages: [1]
  ignore  |  Print  

hadezbladez (290 views)
2018-11-16 13:46:03

hadezbladez (160 views)
2018-11-16 13:41:33

hadezbladez (291 views)
2018-11-16 13:35:35

hadezbladez (72 views)
2018-11-16 13:32:03

EgonOlsen (2152 views)
2018-06-10 19:43:48

EgonOlsen (2178 views)
2018-06-10 19:43:44

EgonOlsen (1367 views)
2018-06-10 19:43:20

DesertCoockie (1984 views)
2018-05-13 18:23:11

nelsongames (1626 views)
2018-04-24 18:15:36

nelsongames (2274 views)
2018-04-24 18:14:32
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46 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‑
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!