- Home /
obstacles avoidance in C#
I want an AI that will move my NPC towards the target but avoid obstacles in its path they may be moving .Please tell me who can get started for it
Comment
Not in C# but shows a method you can convert : http://vimeo.com/9304844
Best Answer
Answer by GamingNewBie · Jan 27, 2013 at 09:30 AM
I think RayCast would be a good way to start with your problem.
void Update()
{
Vector3 fwd = transform.TransformDirection(Vector3.forward);
if (Physics.Raycast(transform.position, fwd, 10))
{
print("There is something in front of the object!");
}
}
http://docs.unity3d.com/Documentation/ScriptReference/Physics.Raycast.html
I edited your answer to make it readable =]
Why not just use :
if (Physics.Raycast(transform.position, transform.forward, 10))
ins$$anonymous$$d of all that Vector3 fwd = transform.TransformDirection(Vector3.forward);