Curious. A physics library for 2D tile-based walking? That's either super overkill, or else you've got a lot more going on in this game then you've mentioned so far. (If you're making a complex game, I strongly suggest you make a few simple games first to get some experience - it seems like you're fairly new to this, and you're likely to get in way over your head and give up on things.)
Pokemon style movement
Re: Pokemon style movement
Any code samples/ideas by me should be considered Public Domain (no attribution needed) license unless otherwise stated.
Re: Pokemon style movement
I understandmilon wrote: ↑Thu Apr 14, 2022 1:06 pmCurious. A physics library for 2D tile-based walking? That's either super overkill, or else you've got a lot more going on in this game then you've mentioned so far. (If you're making a complex game, I strongly suggest you make a few simple games first to get some experience - it seems like you're fairly new to this, and you're likely to get in way over your head and give up on things.)
Code: Select all
-------------------------------
-- i love programming in Lua --
-------------------------------
Re: Pokemon style movement
What part of that snippet code would I have to modify to adjust the speed from one tile to the next, because the movement is a bit too fast for me.
and also, i managed to combine this method with animated spritesheet (anim8 library) and it works nice, but there is a sliding effect,
such that if you press a key slightly in a row, the character doesn't really switch to the next animation frames, he looks like he is sliding
on one frame to reach the next tile. i tried multiple things, not sure how to fix this. i suspect it's because of the keypressed/released
combo, maybe somehow with isDown?
he is not sliding if you continue pressing and holding, but i mean like if you just press once and again shortly after in succession,
he will slide, which looks kinda weird.
Thanks!
and also, i managed to combine this method with animated spritesheet (anim8 library) and it works nice, but there is a sliding effect,
such that if you press a key slightly in a row, the character doesn't really switch to the next animation frames, he looks like he is sliding
on one frame to reach the next tile. i tried multiple things, not sure how to fix this. i suspect it's because of the keypressed/released
combo, maybe somehow with isDown?
he is not sliding if you continue pressing and holding, but i mean like if you just press once and again shortly after in succession,
he will slide, which looks kinda weird.
Thanks!
- Hugues Ross
- Party member
- Posts: 110
- Joined: Fri Oct 22, 2021 9:18 pm
- Location: Quebec
- Contact:
Re: Pokemon style movement
These lines, probably... 2 is the speed value, in pixels-per-frame.What part of that snippet code would I have to modify to adjust the speed from one tile to the next, because the movement is a bit too fast for me.
Code: Select all
x = x + (sign * 2)
Code: Select all
y = y + (sign * 2)
You could also look at this thread for another option, using a lerp will let you control the exact time it takes to move between tiles and shouldn't ever over-step tiles, but it may make continuous motion look a little jerky depending on how you code it.
Hope that helps, I wish I could give you some proper code examples but I really shouldn't rn, I'm still recovering from my health issues.
Re: Pokemon style movement
oh thank you very much, that is indeed what i was looking for! now only thing left is to fix the sliding effect.
edit: ok i fixed the sliding effect, everything works so nice now!
edit: ok i fixed the sliding effect, everything works so nice now!
Re: Pokemon style movement
One more question I have. Using this system, how would NPC movement be implemented?
Logically, it has to have separate logic from player movement, but how to actually achieve this?
I just need to figure out something basic for now, like a trigger that causes a NPC to move in a certain
direction for some tiles. Let's say NPC has to move 10 tiles to the right after I press the m key on the keyboard.
Of course this is a manual trigger for testing, but I am not sure how would I implement this. Cause I tried some
stuff already, but only moves for 1 tile.
Logically, it has to have separate logic from player movement, but how to actually achieve this?
I just need to figure out something basic for now, like a trigger that causes a NPC to move in a certain
direction for some tiles. Let's say NPC has to move 10 tiles to the right after I press the m key on the keyboard.
Of course this is a manual trigger for testing, but I am not sure how would I implement this. Cause I tried some
stuff already, but only moves for 1 tile.
Re: Pokemon style movement
I've made it so:
Let's the path of movement is a list of tiles, for example if the agent stays at position {x=3, y=1} and moves to {x=5, y=2} then the path is
Now you can take path[1] and path[2] as two positions as direction to move.
so if the t is between 0 and 1 you can just interpolate the position as
After the t is higher than 1, just set the t as 0 and remove the first position from path:
If the path[2] not exists, then the target was achieved, set the agent position = path[1] and set the flag that the animation was done.
Also you can use that t as x for the jumping animation
https://www.desmos.com/calculator/tdvm7yxvcp
(Desmos has y axis in other direction, but the formula is right)
Let's the path of movement is a list of tiles, for example if the agent stays at position {x=3, y=1} and moves to {x=5, y=2} then the path is
Code: Select all
path = {
{x=3, y=1}, -- starting position
{x=4, y=1},
{x=5, y=1},
{x=5, y=2}, -- target position
}
so if the t is between 0 and 1 you can just interpolate the position as
Code: Select all
local x = path[1].x + t*(path[2].x-path[1].x)
local y = path[1].y + t*(path[2].y-path[1].y)
Code: Select all
table.remove(path,1)
Also you can use that t as x for the jumping animation
https://www.desmos.com/calculator/tdvm7yxvcp
(Desmos has y axis in other direction, but the formula is right)
Code: Select all
local dy = 4*(t-0.5)*(t-0.5)-1
y = y + 0.25* dy -- low jump on high of 1/4 tile
Re: Pokemon style movement
That is very nice for that system, but I should have been clear, I meant the other system here:
viewtopic.php?p=247379#p247379
How to implement NPC movement in that one? Cause that's the system that I have working nicely right now
and don't really need to use the other one.
edit: ok so I managed to implement NPC movement now in my system, anyway, but thanks so much for help!
viewtopic.php?p=247379#p247379
How to implement NPC movement in that one? Cause that's the system that I have working nicely right now
and don't really need to use the other one.
edit: ok so I managed to implement NPC movement now in my system, anyway, but thanks so much for help!
Who is online
Users browsing this forum: Google [Bot] and 2 guests