I've been trying to make a new game on love2d and I came across a problem with using tile maps, I would like to use simple physics for jumping and moving around in my game but I'm confused on how I could implement it for floating platforms.
For context, here is a link to what I used for the physics in my game.
https://love2d.org/wiki/Tutorial:Baseline_2D_Platformer
How can I implement tile collisions with a platformer character without box2d or physics?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- BrotSagtMist
- Party member
- Posts: 665
- Joined: Fri Aug 06, 2021 10:30 pm
Re: How can I implement tile collisions with a platformer character without box2d or physics?
I am confused which method you ask for here.
Tiles or floating platform? Booth are fundamentally different.
For Tiled detection we place a bigger grid above the pixels, this grid contains the info on what is wall or floor.
Then we collide by simply testing on what field our object is:
if Grid[math.floor(x/tilesize)][math.floor(y/tilesize)]=="floor" then
Floating platforms are simply checked by their boundaries:
if x>platformx and x<platformx+size and y>platformy and y<platformy+size then
This is a bad method for big maps. But works splendid on small ones.
The method is simply to SAVE the position to a variable, then apply the forces:
velocity=velocity+gravitation*time
position=position+velocity*time
Then do the collision check as above, and if it collides simply revert to the saved position and zero velocity.
That way we stay on ground.
Tiles or floating platform? Booth are fundamentally different.
For Tiled detection we place a bigger grid above the pixels, this grid contains the info on what is wall or floor.
Then we collide by simply testing on what field our object is:
if Grid[math.floor(x/tilesize)][math.floor(y/tilesize)]=="floor" then
Floating platforms are simply checked by their boundaries:
if x>platformx and x<platformx+size and y>platformy and y<platformy+size then
This is a bad method for big maps. But works splendid on small ones.
The method is simply to SAVE the position to a variable, then apply the forces:
velocity=velocity+gravitation*time
position=position+velocity*time
Then do the collision check as above, and if it collides simply revert to the saved position and zero velocity.
That way we stay on ground.
obey
Re: How can I implement tile collisions with a platformer character without box2d or physics?
Oh I meant mostly tiles specifically, I was giving an example of the floating platform because the way I have my code set up for the character to treat the horizontal line in the middle of the screen as the ground and ignore everything else.BrotSagtMist wrote: ↑Thu Apr 20, 2023 3:11 am I am confused which method you ask for here.
Tiles or floating platform? Booth are fundamentally different.
For Tiled detection we place a bigger grid above the pixels, this grid contains the info on what is wall or floor.
Then we collide by simply testing on what field our object is:
if Grid[math.floor(x/tilesize)][math.floor(y/tilesize)]=="floor" then
Floating platforms are simply checked by their boundaries:
if x>platformx and x<platformx+size and y>platformy and y<platformy+size then
This is a bad method for big maps. But works splendid on small ones.
The method is simply to SAVE the position to a variable, then apply the forces:
velocity=velocity+gravitation*time
position=position+velocity*time
Then do the collision check as above, and if it collides simply revert to the saved position and zero velocity.
That way we stay on ground.
Who is online
Users browsing this forum: CutePenguin and 4 guests