Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Best method for moving NPCs in 2D world

Author
Message
Richard_6
7
Years of Service
User Offline
Joined: 3rd Feb 2017
Location:
Posted: 21st Jul 2018 04:39
Which methods do you use for moving NPCs sprites when the player is not around (not raycasting) in a 2D world? Here's an example:



I'm just wondering about the movement side by side, not the playsprite animation. Would you use tween chains? raw setspriteposition with conditionals?

GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 22nd Jul 2018 01:57
FTS = GetFrameTime()
inc player.xp, player.xv * FTS
inc player.yp, player.yv * FTS

moving left means setting player.xv to some negative value that corresponds to how fast you want the character to move to the left.
moving right is same only player.xv needs to be set to a positive value.
TI/994a (BASIC) -> C64 (BASIC/PASCAL/ASM/Others) -> Amiga (AMOS/BLITZ/ASM/C/Gamesmith) -> DOS (C/C++/Allegro) -> Windows (C++/C#/Monkey X/GL Basic/Unity/Others)
Richard_6
7
Years of Service
User Offline
Joined: 3rd Feb 2017
Location:
Posted: 22nd Jul 2018 23:40
Gar, such a coincidence... I was checking your platform videos on youtube wondering how you made the enemies waiting moves lol.

Just to make sure I understood, xp is position and xv is velocity?
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 23rd Jul 2018 02:14 Edited at: 23rd Jul 2018 02:15
Ha ha. Yeah if you look at some of the source I've posted around here (which granted I have no idea where those things are now... I need to take some time one day and do a search for all of the projects I share and link them in my signature I think)... they should all basically follow the same patterns. States are used to control everything at the high level... basically it sets the goal like walking, ducking, attacking, dodging, etc. Depending on complexity states may be broken down into one or more Tasks. But anyway.... then at the lower level yes every object has xp and yp specifying its current position and xv and yv specifying its current velocity.

Actually, I am not sure if I have ever shared a project on here for a platformer. I might make a very very basic one to post at some point.
TI/994a (BASIC) -> C64 (BASIC/PASCAL/ASM/Others) -> Amiga (AMOS/BLITZ/ASM/C/Gamesmith) -> DOS (C/C++/Allegro) -> Windows (C++/C#/Monkey X/GL Basic/Unity/Others)
Richard_6
7
Years of Service
User Offline
Joined: 3rd Feb 2017
Location:
Posted: 23rd Jul 2018 13:03
Quote: "I might make a very very basic one to post at some point."


That would be great! Thanks!
Alex_Peres
AGK Master
15
Years of Service
User Offline
Joined: 13th May 2009
Location: The Milky Way Galaxy
Posted: 23rd Jul 2018 15:54
I would recommend calculating every frame this:

DBF = GetFrameTime() * 60

if it runs 60 fps so you just will have 1 and all your settings will stay as it is.

Login to post a reply

Server time is: 2024-11-23 17:41:58
Your offset time is: 2024-11-23 17:41:58