- Home /
How to make AIPath (A*) work on 2D game ?
I have 2D scene which got wall sprites and two vehicle sprites. All of them has 2D colliders. I have GameObject with AstarPath component.
I have created Grid graph, rotated it to 90 degrees by X axis. I have ticked Use 2D Physics and collider type RAY. Then changed size of my grid to make it have larger area.
Then added AIPath and Seeker to my vehicles and made target to each of them.
When I start play mode, both vehicles starts to move each other. However, they also start rotating in Y axis, they must be rotating by Z axis to make them look like steering. What I did wrong?
Is it a top down game? and can't you just lock rotation:
function LateUpdate() {
transform.rotation = Quarternion.identity;
}
or
private var iniRot : Quaternion;
function Start() {
iniRot = transform.rotation;
}
function LateUpdate(){
transform.rotation = iniRot;
}
Yes my game is TOP-DOWN game. I have locked rotation as you asked, used both of them. Now they just don't move.
If you have rigidbody attached to the game objects there are check box options in the inspector to freeze rotation in whichever axis you desire.
Red
Yes I have Rigidbody2D attached to my vehicles, but I don't have any checkboxes in instpector except is$$anonymous$$inematic, FixedAngle.
Are you talking about implementing A* or implementing arongranberg A* pathfinding project. The two are not the same thing, and will result in very different answers.
Please clarify this point.
Answer by Kiwasi · Nov 07, 2014 at 08:57 AM
For arongranbergs in 2D there are a couple of options
Wrap the vector inputs and outputs from the path finding engine in a class that lets you work with your dimensions
Switch your project to work in dimensions that are compatible with the project (ie camera looking down the y axis
Break open the code and switch the dimensions around. You may find someone who has already done this
Use a version of A* implemented specifically for 2D
Implement A* your self (This is not overly difficult for someone of intermediate scripting ability)
Your answer
Follow this Question
Related Questions
A* Algorithm Node Grid Generation 2 Answers
Is there a way for an A* gridgraph pathfinding to consider the collider of terrain trees ? 0 Answers
A* Pathfinding Project Problem with Obstacles 2 Answers
Astar Pathfinding not scanning graph 0 Answers
How to reach 2D Grid from script? How to reach every tilemap location and use them for pathfinding? 1 Answer