Page 1 of 2

Diagonal RPG Collission!!

Posted: Tue Jun 20, 2023 6:45 pm
by Krynn-San
Hey, so I'm making a top-down rpg and i want smooth diagonal collision, as seen in A Link to the Past, or any similar rpg game tbh.

I've heard that the best way was using a velocity and subtracting how much you moved from how much you would have moved, but i dont rlly understand that, I cant find any tutorials, plus I'm moving my character by a speed, and looping for each pixel, and not even using a velocity.

So I was wondering: could I just mark diagonal tiles as similar to solid, but give them individual physics, based on the diagonal type and your direction?? Or would my best bet just be adding velocity?

Thanks in advance if anyone sees this!!

Re: Diagonal RPG Collission!!

Posted: Tue Jun 20, 2023 11:06 pm
by BrotSagtMist
What is your collider code anyway?
How is your map structured? Tiled, free?

Re: Diagonal RPG Collission!!

Posted: Wed Jun 21, 2023 1:09 am
by pauljessup
Velocity is a fancy word for speed, basically, lol.

Re: Diagonal RPG Collission!!

Posted: Wed Jun 21, 2023 9:59 am
by UnixRoot
pauljessup wrote: Wed Jun 21, 2023 1:09 am Velocity is a fancy word for speed, basically, lol.
Speed is the time rate at which an object is moving along a path, while velocity is the rate and direction of an object's movement. It's not the same, velocity is a vector.

Re: Diagonal RPG Collission!!

Posted: Wed Jun 21, 2023 6:17 pm
by pauljessup
I was making a joke, that's all, riffing on the literal dictionary definition of velocity

Either way, I don't think you need velocity to do diagonal movement and diagonal collision, you just need to check both future x and y and not just one or the other...

Re: Diagonal RPG Collission!!

Posted: Wed Jun 21, 2023 6:47 pm
by BrotSagtMist
yee the usual way is just saving the position to a temp value, apply the movement, check if we are in a wall, and if we are just revert to the save.

Re: Diagonal RPG Collission!!

Posted: Wed Jun 21, 2023 7:04 pm
by Bobble68
BrotSagtMist wrote: Wed Jun 21, 2023 6:47 pm yee the usual way is just saving the position to a temp value, apply the movement, check if we are in a wall, and if we are just revert to the save.
This approach does work, though it does mean you'll never be right up against the wall, and means you sort of 'stick' to the wall so you can't slide against it when moving at an angle into it.
A more advanced approach is to move the player to a position on the line of movement that is exactly against the surface of the wall, that way you get right up close to the wall. (Granted, this version only solves the first issue)

Re: Diagonal RPG Collission!!

Posted: Wed Jun 21, 2023 7:06 pm
by darkfrei
I am using the system:
Check the movement. If ok, then do the movement else don't do the movement. It's very universal and simple for realization.

Re: Diagonal RPG Collission!!

Posted: Wed Jun 21, 2023 7:59 pm
by BrotSagtMist
Yee, it works fine for rpgs, but bobble has a point, any physics simulation with gravity and you get a weird floating motion above obstacles :D
Then well need our freaking movement vectors.

Re: Diagonal RPG Collission!!

Posted: Wed Jun 21, 2023 8:22 pm
by pauljessup
Okay, yeah, that's true. For not sticking on walls movement vectors are hella important