- Home /
2D Platformer AI Jump?
Hello,
I have a problem with creating a 2D platformer game (in C#). The platformer game is a game where you have to jump from platforms up to another platform to get higher and higher.
Now I need an AI that follows the quickest way to the player, and also jumps from one platform to another repeatedly to get higher.
How do I let the AI know when it can jump? (If he can also make the jump to a higher platform). How do I let him jump to the right position to the right platform at the right time?
I can't seem to find anything related to this anywhere, I have looked everywhere.
Any kind of help is appreciated.
Answer by Klarax · Feb 11, 2014 at 02:03 PM
i would probably go with putting triggers on each side of the platform, and then on enter trigger -> jump sctipt kicks in
I have tried this before. But my AI is checking where the player is (on which side of him on the x axis), and he will move to that direction. Also, the AI doesn't always make the jump. It will also bug when landing and when you have to jump right away again.
Here's my script so you see what I did: http://pastebin.com/CBeFN5T3 or http://pastebin.com/raw.php?i=CBeFN5T3
im not sure how to do this as im still learning myself. but i would suggest needing to implement a ray cast down in front of the AI. if no ground detected, then jump.
That should fix both issues. as the AI will wait til very near the edge so will make the jump, and on landing there will be ground again and no second jump
Answer by Ankit Priyarup · Feb 11, 2014 at 02:56 PM
You can use unity 4.3 2D features. Then you need to download Unity standard asset beta from here
Import the character into a fresh scene and create script for main camera to move vertically in y position.Place a gameobject (cube) on the bottom (out of main camera) and create a script to show gameover when player get collide with that gameobject. In main camera make an empty gameobject and place a script called spawner you can get the script and other related help from here. http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/infinite-runner
Here's the link for sample asset beta https://www.assetstore.unity3d.com/#/content/14474
I know how to do all that, and how to make a 2D platformer. But the problem is the AI. The AI needs to jump on the right time. It needs to follow the player and also jump on the platforms so he can make it and get higher in the level. The links you gave look very useful but not for this problem. Thanks for the links because they seem useful in the future.
I dunno if this will work but have you tried putting a frontcheck of sorts that will hit a collider at the end of the platform that will cause it to jump?