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:
(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!
[SOLVED] RPG Party System
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
[SOLVED] RPG Party System
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."
-
- Party member
- Posts: 234
- Joined: Mon Aug 29, 2016 8:51 am
Re: RPG Party System
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. Once gridified, you need to keep in every character/npc his last position on the grid. 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. Here's some example code for doing that:
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. Once gridified, you need to keep in every character/npc his last position on the grid. 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. 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
- zorg
- Party member
- Posts: 3468
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: RPG Party System
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.
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.
Me and my stuff True 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.
Re: RPG Party System
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.
Re: RPG Party System
Could you elaborate a little more? Also, Jumper doesn't have very detailed documentation... how would I go about using it?
Would this be easier/more efficient than using a grid and a pathfinder? If so, how do I actually record the points?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.
"I am a tomato. My favorite food is tomatoes. Tomatoes are the best. I eat them everyday. I love to hear them scream."
Re: RPG Party System
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
Re: RPG Party System
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."
Who is online
Users browsing this forum: Bing [Bot] and 5 guests