Diagonal RPG Collission!!

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
BrotSagtMist
Party member
Posts: 664
Joined: Fri Aug 06, 2021 10:30 pm

Re: Diagonal RPG Collission!!

Post by BrotSagtMist »

Well if it is a tiled map we can also modulo it to the wall and get away without advanced math.
But we could then fall though the floor if the fps drop.
Its always a tiny detail :D
I just wrote a game where i botched up exactly that checking and the result is that i can walk on the ceiling too, but i freaking love this bug, i should make a proper one with that mechanic.
obey
Krynn-San
Prole
Posts: 6
Joined: Tue Jun 20, 2023 6:49 am

Re: Diagonal RPG Collission!!

Post by Krynn-San »

Ahh, well: my map is tiled, so far im just using square tiles and marking them as solid or nonsolid. I'm just moving my character by 1 pixel at a time (looping for speed tho).

An answer I got was:

"the general way this is done is when your character collides with a wall you subtract the difference of how much they did move from how much they would have moved from their velocity
then you adjust their velocity vector to be parallel with the wall
this will make them slide along it"

and i could add velocity but would that work or would I have to change how im doing things??
User avatar
BrotSagtMist
Party member
Posts: 664
Joined: Fri Aug 06, 2021 10:30 pm

Re: Diagonal RPG Collission!!

Post by BrotSagtMist »

Again you havnt answered:
What is your collider code?
Also that quote is pretty mixed up, as in, does that even match the question?
Top down RPG, you should not have velocity or sliding and all that.
obey
Krynn-San
Prole
Posts: 6
Joined: Tue Jun 20, 2023 6:49 am

Re: Diagonal RPG Collission!!

Post by Krynn-San »

Ahh, makes sense.. im just literally checking the corners of my sprite, against the solid map tiles and preventing movement if it's solid anywhere.
User avatar
BrotSagtMist
Party member
Posts: 664
Joined: Fri Aug 06, 2021 10:30 pm

Re: Diagonal RPG Collission!!

Post by BrotSagtMist »

I have still no idea what you do there, you seem to be lost in something complicated.

Just saying on an rpg movement the whole process is just:

Code: Select all

--for moving say left
 if love.keyboard.isDown("left") then x=x-Speed*dt end
 --for collid checking 
  if Map[math.floor(x/Tilesize-Spritesize)][math.floor(y/Tilesize)] then   --revert to last point   end
 
So in total maybe 8 lines with all directions.
obey
Krynn-San
Prole
Posts: 6
Joined: Tue Jun 20, 2023 6:49 am

Re: Diagonal RPG Collission!!

Post by Krynn-San »

yea, that's what I'm doing, except I can't just keep referencing map[x][y] because some tiles are diagonal, half-solid, and i want to smoothly walk along them
User avatar
darkfrei
Party member
Posts: 1213
Joined: Sat Feb 08, 2020 11:09 pm

Re: Diagonal RPG Collission!!

Post by darkfrei »

Krynn-San wrote: Thu Jun 22, 2023 2:29 am yea, that's what I'm doing, except I can't just keep referencing map[x][y] because some tiles are diagonal, half-solid, and i want to smoothly walk along them
There is two main mechanics:

1. Step safe:

Code: Select all

local dx, dy = getMovementInputs ()
dx = dx * speed * dt
dy = dy * speed * dt
if canMove (player, dx, dy) then
	doMovement (player, dx, dy)
end
Here any collision in movement direction glues you to the solid, but you can go near the solid without sticking.

2. Push back:

Code: Select all

local dx, dy = getMovementInputs ()
dx = dx * speed * dt
dy = dy * speed * dt
doMovement (player, dx, dy)
pushBack (player)
Where pushBack function search collidings, calculate the smallest vector dx, dy to push you out of solid. You can slide by the wall.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
BrotSagtMist
Party member
Posts: 664
Joined: Fri Aug 06, 2021 10:30 pm

Re: Diagonal RPG Collission!!

Post by BrotSagtMist »

BrotSagtMist wrote: Tue Jun 20, 2023 11:06 pm How is your map structured? Tiled, free?
Krynn-San wrote: Thu Jun 22, 2023 2:29 am because some tiles are diagonal
:x
I now get it.
Youre working with a free map, not with tiles.
All this comments above where written under the impression your map has squared elements.
If your elements are triangles of course this will be a lot of more work.and normally takes a complete different approach.
But you can maybe get away with setting your movement code within the map:
map[x][y]()
That way you can have adjusted movements depending of where you step on.
obey
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 6 guests