- Home /
A* Pathfinding with mecanim and rotation
Hi!
So basically I need help to make some AI with arongranberg's A* pathfinding project. I can not find a lot of documentation about this so I can't figure out how to make a good AI. I followed the get started tutorial but the AI functions very poorly. My main questions is how I can use mecanim and rotating in the direction it is walking in. The script from the documentation uses Character Controller with Simple move.
So any links to any good tutorials or documentation about this really helps!
If you want to see my code, simply look at the code here: http://arongranberg.com/astar/docs/_astar_a_i_8cs-example.php It is pretty much the same.
Thanks in advance!
I am also currently in the same exact situation and going from 1 thread to the next hoping for any kind of answer...
Since yours is from 2015, have you found a solution since then?
The characters with the "Controller" all go haywire and glitch-rotate all over the place ins$$anonymous$$d of "focusing" towards their objective/waypoint...
Would love to find an actual solution for this... (will keep this bookmarked and come back and post an answer should I manage to find or create one)
I'm sorry to tell you that I never got anywhere with that. I don't even remember what project this was for. But I would suspect you could do something like getting the next waypoint's position and then making it look in that direction, if that is to any help.
Answer by FireHawkX · Nov 21, 2016 at 08:09 PM
Here is an answer!! :)
Vector3 relativePos = TARGET.position - transform.position;
//replace TARGET with what they should "look at"
Quaternion rotation = Quaternion.LookRotation(relativePos);
transform.rotation = rotation;
By adding that code right after the "controller.SimpleMove (dir);" of the AStar Pathfinder, it makes all of the units look at their target at all time!
I did something similar to this. I created a custom function in AILerp.cs that would rotate the transform of our transform towards a target transform using a coroutine. $$anonymous$$ind you, this was for 2D.
IEnumerator RotateTowardsTransformCoroutine(Transform FOV, Transform transformToFace, float rotationSpeed)
{
Vector3 previousEuler = new Vector3(0, 0, 0);
bool run = true;
while (run)
{
RotateTransform(FOV.transform, transformToFace.transform.position - transform.position, rotationSpeed);
if (previousEuler - FOV.transform.eulerAngles == Vector3.zero)
{
run = false;
}
else
{
previousEuler = FOV.transform.eulerAngles;
yield return null;
}
}
}
Your answer
Follow this Question
Related Questions
Animation works, pathfinding works, but they don't work together. 1 Answer
Look rotation makes sudden changes 1 Answer
How to rotate object to face toward the path using Astar pathfinding? 0 Answers
Top-down character running animation based on facing direction 0 Answers
A* PathFinding Radius sphere 1 Answer