2D game

I’m a total noob with this stuff, so please bear with me. I’m trying to use A* in a 2D game with y axis up and x axis pointing right. So when I start a Grid Graph, I set x rotation to -90 to get it oriented with my 2D world. In my world there is no “floor” (underwater game) there are only walls. So i turn off height test and set the collision testing mask to the layer that has my walls on it. I run scan and this brings me to my first question. What are the rainbow colored lines (horizontal)? I see the red cubes covering my walls which I understand is what I want, but I don’t know what the colored lines mean.

Moving on, I add the Seeker component and AI Path script to one of my enemy sprites and set the target to another sprite. When I run the game I see the green path is drawn between the two, great. But the eney starts to rotate in z space, which for a 2D game is not good. Then it gets to a point where it should turn, but it just stops there. To eliminate the rotation, I tried commenting out line 277 in AIPath. If I do that the object does not move along the path, but instead just starts falling in z direction.

Any help is appreciated. In the meantime I will be reading more docs and code :slight_smile:

Think I found most of what I need in old forum…

http://www.arongranberg.com/?s=rainbow

Hi

The colored lines are different areas of the graph which cannot be reached from each other. You probably don’t want that and the setting I think you should change is the Max Climb setting (set to 0 to disable) or alternatively Max Climb Axis (set to Z axis).

Here is a guide on how to use the A* Pathfinding Project for a 2D game. It is a bit old so some have changed since then, but it is in large part still valid.
http://www.rocket5studios.com/tutorials/make-a-2d-game-with-unity3d-using-only-free-tools-beginning-enemy-ai-with-a-pathfinding/

The AIPath script is designed for normal (i.e XZ) movement. You will have to write a custom AI controller for that to work, or you could rewrite the AIPath script.

Yeah, I looked at the rocket5studios page. Unfortunately, it hasn’t been very helpful as it is pretty specific to their demo game. Any tips for rewriting the AIPath script for 2D movement would be great. Thanks!

If your game is top down. You could basically exchange every “somevector.z” piece of code to “somevector.y” in the AIPath script and change the scene’s gravity (unity physics settings) to something on the Z axis.
The AIPath script would not work in a platformer game I am afraid.

Yep, that is pretty much what I ended up doing. In some places I also had to go the other way around y > z. I didn’t try to preserve the “slowdownDistance” part, but other than that it’s working well.

Hi there! I’m coding a 2D adventure game with some platforming sections, would this work? It’s getting kinda hard try to make enemies jump, and I’m also experiencing the same rotation issue than sleekdigital. I’ve managed to cancel the enemy’s gameObject rotation, but that results in it not being able to move.

First of all, can I somehow deactivate object rotation when it is following a path? And also, how should I try a jumping solution for enemy AI paths?

Thx!

Not sure about the jumping part, but I can send you my modified AIPath file, I think.

That would be great!

As for the juming part, I’m now trying with a raycasting solution. When the “enemy” object’s raycast does not hit ground (aka there’s a hole), it sends him a “jump” order. I’m still on it, but I think it can work.

BTW miguelteku@gmail.com

Hey Sleekdigital, I would be interested in your edited Aipath file!

My email threepeasoup@gmail.com

Hello is it possible to send me the modified aipath please? delmarle@me.com

If possible, could someone send this modified script to markus.santaniemi@gmail.com

I tried to make it work but I suppose something went wrong…