Hello. I have a simple event to make the player face who he is talking to, but I am sure there must be a cleaner way of doing this than pasting the same events for each NPC. The only difference between each block is a variable check. Each NPC is a separate object - not separate animations within one object. This is unavoidable because NPCs may vary in size and have various animations each.
My question: how do I make a single event that will flip my character for any NPC he talks to?
I tried grouping them to see how that would behave. The player would flip when in collision with either NPC in the group, but he was only using the X position of the first NPC.
I think the answer will help me way beyond this small problem. I’m getting on well with GDevelop, but more dynamic stuff is a little out of reach and that means my events are repetitive and verbose. They work, but I know they could be better. Thank you.
Have you tried putting all the NPCs into an object group?
According to the limited knowledge I have about that, I would at the beginning of the game, in the scene editor, give each NPC an object variable “name” that record their own name.
In scene editor I would also group all NPCs in a group called NPC.
Then for checking if frodo is on right or left that the NPC he’s talking with, I’d do like that :
That means the event will try each instance of objects in the group NPC. For each of them it will check if that’s the one frodo is talking to.
(if you have several instances of a same NPC object, maybe you’ll need to add a condition like “distance between frodo and NPC< something” , so only the instance he’s talking to would work)
Please someone who know better confirm it’s the best way to do it…!?
I think there’s no other way to dynamically access an object (I don’t really know why).
Thanks Bluzima for your time, but that doesn’t seem to work for me. The player faces the correct way for the first npc (trevor), but it breaks for brenda: none of the actions for that event work when I talk to her.
Did you added the brenda object to the NPC object list, give her the instance variable
name and make sure the case is correct?
I haven’t used ‘repeat for each instance before’. That did it!
Thank you @Bluzima for going to the trouble of creating the events and solving my problem - I’m sorry I didn’t realise it right away! Thanks also @MrMen and @beanmatt for nudging me along.