• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
David Zeek

Tile-Based Collision\Physics Problem

12 posts in this topic

Hello guys this is my first post and I hope I'm posting it in the right place..

so I'm working on a tile-based game: 16x16 player, 16x16 tiles. the hitbox for the player is 16x16.

I got a problem that I have no idea how to solve, I tried different type of collisions to do it, basically the player's velocity is so high that he just flys above 1-tile holes..

let's say i'm trying to jump into 1 space hole vertically horizontally or whatever and I can't because of my velocity, even if it's very low, 1 pixel off is enough to make him not fit inside the hole, and I have no idea what to do, help?
0

Share this post


Link to post
Share on other sites
If I understod right: try 8x8 (or similar) hitbox from the center of player?
0

Share this post


Link to post
Share on other sites
I don't want to reduce the hitbox, I want to keep it the way it is but get the player to somehow still fall through holes without reducing the hitbox
0

Share this post


Link to post
Share on other sites
Most games just ignore this problem. If it's a tight fit and you're moving fast, you slide right over. If you want to improve it just a little bit, then you could divide the velocity by 2 and them move twice, effectively doubling the frame rate so you can be moving at twice the speed before missing.

Alternatively, you could do some kinda funky stuff, like, if you're going down and the bottom edge of the collision box is going to cross a tile boundary, then move down to that tile boundary (without bothering to check collisions since you couldn't hit anything without changing tiles), and then do the X motion, and then do the rest of the Y motion. That way regardless of how fast you're falling, you'll always be lined up properly to squeeze into small gaps in walls. Not sure how to apply this to gaps in floors/ceilings at the same time though.
0

Share this post


Link to post
Share on other sites
Divide and conquer: Move the objects pixel per pixel. If there are more than one possible movement axis (x and y as in your example) check both in a loop.

Pseudo code:

[code]
DeltaX, DeltaY hold the intended movement.

while ( ( DeltaX != 0 ) || ( DeltaY != 0 ) )
{
if ( DeltaX > 0 ) Move1PixelRight
if ( DeltaX < 0 ) Move1PixelLeft
if ( DeltaY > 0 ) Move1PixelDown
if ( DidNotFallYet ) CheckIfPlayerCanMoveDown1Pixel
}
[/code]
0

Share this post


Link to post
Share on other sites
You can't use the velocity to move directly.
You need to use smaller step, such as "tileSize - 1", to move, until the total steps meet the velocity.
If the velocity is 20, and your tile size is 16, you first move 15 pixels, then move another 5 pixels.

@Endurion,
Isn't moving one pixel too small and may hit the performance? Any special reason?
1

Share this post


Link to post
Share on other sites
I don't want to make the player smaller, and I tried all these stuff like dividing the velocity, like merging the x & y velocity and move 1 pixel at a time but it's like very annoying and no method works.. like I'm always led into problems and I know what causes them but I don't know how to fix it.. i feel like i'm asking for something that was never done before lol i know it's weird that everything is 16x16 and everybody tell me to change the hitbox but i really want everything to be 16x16..

*edit: i tried reducing the hitbox and it still flys above the gaps, i reduced it to about 3 pixels in every side
0

Share this post


Link to post
Share on other sites
Making the player smaller wont help!.. why not make tetris instead of this game..

wqking got the best answer.. I think you have to test if you must use "tileSize - 1" instead of "tileSize"..
now when u find a hole underneath, align the player to it and make it fall, whatever gravity u have. Edited by SloydD
0

Share this post


Link to post
Share on other sites
One idea is instead of using one 16x16 hit box, you can use 4 4x4 hit boxes and only react to collisions that occur to 2 or more. This gives you the same size as before and allows you to have "soft" collisions. This would be no more complex than the other "solutions" and allows you finer grain control over collision response.
0

Share this post


Link to post
Share on other sites
This is how my collision detection works in the game i'm creating in SDL.

[CODE]
bool MasterEntity::collisionDetection(SDL_Rect *A, SDL_Rect *B)
{
bool colFlag = false;
int aX, aXW, aY, aYH, bX, bXW, bY, bYH;
//collision points of object A
aX = A->x;
aXW = A->x + A->w;
aY = A->y;
aYH = A->y + A->h;
//collision points of object B
bX = B->x;
bXW = B->x + B->w;
bY = B->y;
bYH = B->y + B->h;
if(aXW > bX && aX < bXW && aYH > bY && aY < bYH)
{
colFlag = true;
}
return colFlag;
}
[/CODE]

[left]From your initial post when you wrote "[left][background=rgb(250, 251, 252)][font="helvetica, arial, verdana, tahoma, sans-serif"][color="#282828"][size="2"]basically the player's velocity is so high that he just flys above 1-tile holes.."[/size] i'm brought back to a problem i had on a game i developed a few month back. Are you sure that you are hit testing the NEXT position the character till take and not the one it currently has.[/color][/font][/background][/left]
[left][background=rgb(250, 251, 252)][font="helvetica, arial, verdana, tahoma, sans-serif"][color="#282828"]Lets say you char has these values. X = 5; Y = 5; and you press your left key which will increment X by 5 and Y by 0. To have a successful collision-detection you need to make sure that you are searching for a collision in X = 10 and Y = 5 BEFORE you let your character move. If there is a collision simply don't move him, if not feel free to let him move.[/color][/font][/background][/left]
0

Share this post


Link to post
Share on other sites
I just read your post and i think i might have gotten it wrong in my previous post...

If I've gotten it right this time i'd suggest you make a function to detect if the character has 2 blocks near him (with further collision detection) and if he has just let him slip through and don't care about the collision restriction.
0

Share this post


Link to post
Share on other sites
Why not just use a hit box on the hole when player hits hole move player to centre of the hole and and let him full through.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0