Pokemon style movement

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
milon
Party member
Posts: 472
Joined: Thu Jan 18, 2018 9:14 pm

Re: Pokemon style movement

Post by milon »

ATS wrote: Sun Apr 10, 2022 4:13 pm One more thing, I'm using the Windfield physics library and I'm having trouble colliding with this script you wrote, how can I solve this?
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.)
Any code samples/ideas by me should be considered Public Domain (no attribution needed) license unless otherwise stated.
User avatar
ATS
Prole
Posts: 20
Joined: Mon Jun 28, 2021 3:25 am
Location: Brazil
Contact:

Re: Pokemon style movement

Post by ATS »

milon wrote: Thu Apr 14, 2022 1:06 pm
ATS wrote: Sun Apr 10, 2022 4:13 pm One more thing, I'm using the Windfield physics library and I'm having trouble colliding with this script you wrote, how can I solve this?
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.)
I understand :o:

Code: Select all

-------------------------------
-- i love programming in Lua --
-------------------------------
stepps
Prole
Posts: 19
Joined: Mon Feb 08, 2021 8:57 pm

Re: Pokemon style movement

Post by stepps »

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!
User avatar
Hugues Ross
Citizen
Posts: 85
Joined: Fri Oct 22, 2021 9:18 pm
Location: Quebec
Contact:

Re: Pokemon style movement

Post by Hugues Ross »

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.
These lines, probably... 2 is the speed value, in pixels-per-frame.

Code: Select all

x = x + (sign * 2)

Code: Select all

y = y + (sign * 2)
Since this was intended as a minimal example, there's no delta-time or fractional pixel movement, this could be why it's fast for you. One thing to note, if you change the calculations to use delta-time or make the speed not a multiple of your tile res, you'll also need to adjust the "still moving" check for over-stepping or else you'll have the player walking multiple tiles from one button press.

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.
stepps
Prole
Posts: 19
Joined: Mon Feb 08, 2021 8:57 pm

Re: Pokemon style movement

Post by stepps »

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!
stepps
Prole
Posts: 19
Joined: Mon Feb 08, 2021 8:57 pm

Re: Pokemon style movement

Post by stepps »

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.
User avatar
darkfrei
Party member
Posts: 1168
Joined: Sat Feb 08, 2020 11:09 pm

Re: Pokemon style movement

Post by darkfrei »

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

Code: Select all

path = {
  {x=3, y=1}, -- starting position 
  {x=4, y=1}, 
  {x=5, y=1},
  {x=5, y=2}, -- target position 
}
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

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)
After the t is higher than 1, just set the t as 0 and remove the first position from path:

Code: Select all

table.remove(path,1)
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.


:awesome:
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
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
stepps
Prole
Posts: 19
Joined: Mon Feb 08, 2021 8:57 pm

Re: Pokemon style movement

Post by stepps »

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!
Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests