Make support characters follow hero

0 favourites
  • 8 posts
From the Asset Store
Comprehensive localization solution for Construct 3 projects, no addons required!
  • Hey there!

    So, imagine a game where the sidekick is always following the hero, like Tails following Sonic or one monkey following the other in the Donkey Kong games. How can it be done in Construct? I suppose they need at least a bit of AI involved so they could overcome obstacles in the game or we would need at least some kind of mirrored movement of the hero, but with some delay.

    Some bonus scenarios:

    1: In case the sidekick gets left behind, it comes back to the screen by itself (like Tails);

    2: How to swap controls with the sidekick upon pressing a key or death of the hero (like in Donkey Kong)?

    Thanks in advance!

  • Hmm so the simple answer would be using lerp(self.x, player.x, 0.05) and the same for y. That works well mostly for a floating sidekick but not so much for a grounded one.

    I think one way would be to constantly write the players coordinates and animation into an array (perhaps at 0.1 sec interval if you need to conserve performance) and have the sidekick set animation / move to said coordinates with a delay.

    You could also make something like an AI or simulate the controls with the platform behavior at a delay but that opens up some extra issues that you'll need to solve (like what if the AI jumps into a pit, what if it gets stuck,...)

  • yeah, it entirely depends on what your world looks like - is it a top down view? side scrolling? isometric? what kinds of obstacles are there?

    path finding would be another option.

    see this thread for a "Pet Follow" example I made for someone a while ago...

    https://www.construct.net/en/forum/construct-3/how-do-i-8/stack-movement-sine-behavior-140036?kws=pet%2bfollow

  • Thank you for your replies :)

    WackyToaster — I'll give lerp a go, setting the sidekick to mimic the hero's animations (walking, jumping and so on) so it won't just slide behind the character.

    AllanR It's a platformer like in the examples I gave. I didn't think of pathfinder before because honestly, I'm kinda new to it and I didn't figure how to combine pathfinding movement with character animations yet (telling pathfinding that doing this or that along the way should trigger animations x and y). I'm gonna try your capx from the linked thread and see how it goes. Thank you so much!

  • For platform try Pin using chain style.

  • Heh, absolutely true! Rope style pin could work really well for the most part and requires the least amount of work.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • yep lots of options, you could use an array like this.

    https://www.sizzle-games.com/follow.capx

  • You guys are awesome, thank you for the tips! I tried all of the methods except for the Array sizcoz suggested, because honestly, I started on construct 3 a month ago and still haven't figured out how to effectively use Arrays (but I'll get there, I know they're a big deal).

    WackyToaster and newt, Rope worked a bit, but with some problems listed below.

    AllanR, your capx helped a lot, but I couldn't figure out some details from it that I'm listing here.

    I'm leaving a c3p with the problems I'm facing here (don't know how to save in capx), I would appreciate if you guys could help me out here.

    drive.google.com/file/d/1cJIwNZ_6VJg4k2I2O6-6U6-leHAPA2pS/view

    The problems are listed in the event sheet as comments, but are basically those:

    - I can't make the sidekicks follow each other in a soft, lerp way;

    - Make a smoother turn for the sidekicks when the hero turns from one side to the other;

    - Make them able to jump after the hero;

    - If "Hero" turns around facing a wall, the sidekicks won't cross that wall and get stuck like it's happening atm. Instead, they'll simply stop mid movement until the hero gets farther from the wall. (this one is super annoying because it's making the sidekicks get inside the wall and die/fall).

    Issues:

    - The lerp isn't working on the Y axis because I don't want the sidekicks to float, so the Every tick = lerp Y is nullifying the gravity;

    - Trying the Pin - Rope behavior gets close but makes the sidekick tremble for some reason, the following isn't soft and when the hero turns around, the sidekick instantly changes y position (which shouldn't happen).

    An important note is that the sidekicks are supposed to be cats, so floating behaviors won't work here (a shame, because they were way easier to implement).

    Thank you SO much!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)