[SOLVED] RPG Party System

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.
Post Reply
Zorochase
Prole
Posts: 21
Joined: Sun May 21, 2017 10:40 pm
Contact:

[SOLVED] RPG Party System

Post by Zorochase »

Hello,
I'm currently working on an RPG, and I'm having some trouble trying to create a working party system. What I mean by "party system" is a group of characters that follow a leader in a line. I need to be able to add and remove characters from the line, regardless of the position they are in within the line, and I should be able to set the leader of the line on the fly.

Basically, I want to replicate this:
party.gif
party.gif (497.27 KiB) Viewed 6478 times
(This is from the Mother 4 Blog; I did not create anything you see, nor do I claim to own it.)
Note that the characters in the image above are not locked to a grid; the leader can move wherever they please and the followers follow their footsteps.

As far as I know, this same question has been asked once before on these forums, but the OP seems to have answered their own question with prototype code that would need to be changed to allow for adding/removing to/from the party.
That discussion is here. I'm also not sure if that prototype code takes collisions into account; say, if the leader walks into a wall and stops moving, but the player continues to hold down the move key, if the other followers will still be able to walk through the wall or if the line order would get messed up.

I'd really appreciate your help, thank you!
Last edited by Zorochase on Sat May 25, 2019 7:41 pm, edited 1 time in total.
"I am a tomato. My favorite food is tomatoes. Tomatoes are the best. I eat them everyday. I love to hear them scream."
KayleMaster
Party member
Posts: 234
Joined: Mon Aug 29, 2016 8:51 am

Re: RPG Party System

Post by KayleMaster »

Step 1: Gridify your game
You think it's not, but really I think that game just uses a really small grid (8x8 maybe?) so it's barely noticable to the player, but still eases the programmer. A seasoned gamedev can see that the movements are not pixel by pixel but more like 8 pixels at a time. Again, I may be wrong, but that's just what I think.
step1.png
step1.png (10.43 KiB) Viewed 6449 times
Once gridified, you need to keep in every character/npc his last position on the grid.
step2.png
step2.png (10.5 KiB) Viewed 6449 times
After you recruit someone, use pathfinding (See jumper) to find the path to the player's last location. This path should be updated everytime the player moves.
When you recruit more than 1 NPC's, instead of going to the player's last position, you go to the player's last recruited npc position. That way you form a snake of sorts. You can use linked lists for this.
step3.png
step3.png (8.51 KiB) Viewed 6449 times
Here's some example code for doing that:

Code: Select all

local player_obj = {...}

local npc1 = {...}
local npc2 = {...}

function npc1:follow() 
	local tail = player_obj
	if tail.follower then
		repeat
			tail = tail.follower
		until tail.follower == nil
	end
	tail.follower = self
end
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: RPG Party System

Post by zorg »

On the other hand, there shouldn't be any difference between a 8x8 grid and an "1x1" one, i.e. no grid at all, just pixels; at most, it'd be less performant.

Did you try adapting the methods of the thread you previously linked? From what i can tell, jasoco's code didn't move the party members further based on key input if they were stopped by something, it just didn't account for collisions between the party members.

Adding/Removing/Setting the leader can also either be just a simple add node to end / remove node from wherever / reorder nodes, and moving enough will fix the discrepancies, or you can also make it a bit more complicated by actually forcing a visual update so that the characters will conform to the new "status quo" (near) instantly, instead of them needing to move a bit first. :3
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: RPG Party System

Post by raidho36 »

Alternatively, you can record your leader character's positions for up to certain distance, and make follower characters take the locations on that path at a given offset from the leader. You can also make the "join the line" animation by interpolating between NPCs original position to its desired position on the path, as shown in the OP gif.
Zorochase
Prole
Posts: 21
Joined: Sun May 21, 2017 10:40 pm
Contact:

Re: RPG Party System

Post by Zorochase »

KayleMaster wrote: Tue May 21, 2019 7:23 am Step 1: Gridify your game
Could you elaborate a little more? Also, Jumper doesn't have very detailed documentation... how would I go about using it?
raidho36 wrote: Tue May 21, 2019 1:21 pm Alternatively, you can record your leader character's positions for up to certain distance, and make follower characters take the locations on that path at a given offset from the leader. You can also make the "join the line" animation by interpolating between NPCs original position to its desired position on the path, as shown in the OP gif.
Would this be easier/more efficient than using a grid and a pathfinder? If so, how do I actually record the points?
"I am a tomato. My favorite food is tomatoes. Tomatoes are the best. I eat them everyday. I love to hear them scream."
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: RPG Party System

Post by raidho36 »

Code: Select all

local path = { }

function player:move ( )
  ...
  table.insert ( path, 1, self.position )
  if #path > 400 then
    table.remove ( path )
  end
  npc1.position = path[ math.min ( #path, 100 ) ]
  npc2.position = path[ math.min ( #path, 200 ) ]
  npc3.position = path[ math.min ( #path, 300 ) ]
  npc4.position = path[ math.min ( #path, 400 ) ]
end
Zorochase
Prole
Posts: 21
Joined: Sun May 21, 2017 10:40 pm
Contact:

Re: RPG Party System

Post by Zorochase »

That code worked; I just had to add a check to make sure the player was moving. Thank you!
"I am a tomato. My favorite food is tomatoes. Tomatoes are the best. I eat them everyday. I love to hear them scream."
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 124 guests