- Home /
2D Platformer - How Do I Replicate Inputs And Delay Them?
My game without animation sprites: http://z7r9r0.blogspot.com/2015/05/game-test-5272015.html
I'm using a health system similar to Donkey Kong Country's where the player is followed by another character as their second life/spare hit. YouTube video example: https://youtu.be/W_kI5xOQ0Lc?t=43s
Also Super Mario Galaxy's Mario Cosmic Clones copies players inputs at a delayed time which is similar to the following character effect I'm trying to replaicate. YouTube video example: https://youtu.be/MMB0Sdociw0?t=2m4s
Main question I am trying to solve is if the second character follows the players inputs how do I get the sprites and game objects to not intersect? I am using my own physics to move the player around, not Unity's physics.
Any references or outlines I should look at to accomplish this effect? I can't seem to find anything online yet. I believe I need to find something similar to the classic game Snake since the tail mimics the players inputs/position but at a delayed time. Any help in the right direction will help. I just want to start scripting this today but don't know where to start. I only know Javascript at the moment so anything in Javascript I'll be able to read and understand. Thank you.
Reddit post/comments/answers: https://www.reddit.com/r/Unity3D/comments/37gwt0/2d_platformer_how_do_i_replicate_inputs_and_delay/
Answer by virgiliu · May 27, 2015 at 03:35 PM
Move each input handler to a separate method, for example move the jumping logic in Jump() and call that method when jump is pressed.
After calling Jump() invoke it again for the secondary character with a short delay (a guesstimate would be around 0.5s or 0.7s) .
http://docs.unity3d.com/ScriptReference/MonoBehaviour.Invoke.html
Both game objects should have the same methods, like Jump, Move, etc, so that they can be invoked.
Or you could push the method names in an array then pop & invoke in Update().
Or add a distance joint between the game objects and make the secondary character kinematic.
Does it matter if there are moving platforms that only one character can fit on. I know from this example that when jumping onto a moving platform D$$anonymous$$ moves where the player was ins$$anonymous$$d of standing on the platform: https://youtu.be/W_kI5xOQ0Lc?t=43s
Thanks for the Unity doc page
Jumping might be tricky, especially with landing on moving platforms. You might want to treat those as a special case, for example store the landing position of the main character and on the secondary character override the jump method so that the character lands where the first one was.