- Home /
Help with rigidbodies and follow transform
Hello, so I have been experimenting with basic A.I systems in unity and I put together a bit of code that seems to work alright.
My dillema is that I want the enemy to follow my player and collide with objects while doing so, for example: when moving towards my player I want it to colide with a small hill/bump infront of it.
To do this I added a rigidbody and a box collider (I tried each collider) and now it will collide with objects, but instead of following it will bounce around randomly, maybe fly off into the air or go backwards.
Does anyone have a way to fix this?
var target : Transform;
var speed : float = 3;
private var fixedCoordinate : int = 0;
var follow : boolean;
var lookAt : boolean;
function Update()
{
if(Input.GetKeyDown(KeyCode.F))
{
follow = true;
}
if(Input.GetKey(KeyCode.R))
{
lookAt = true;
}
if(lookAt)
{
transform.LookAt(Vector3(target.position.x, fixedCoordinate, target.position.z));
}
if(follow)
{
this.transform.Translate(Vector3.forward * speed * Time.deltaTime);
}
}
if anyone has a fix for this that would be great! Thanks!
Answer by Hiten2012 · Feb 20, 2015 at 01:44 AM
Don't know perfect answer as per given code, but i seems as per your scenario of work with AI and enemy follow, unity have concept of "Navigation and Path findion", http://docs.unity3d.com/Manual/Navigation.html
Your answer

Follow this Question
Related Questions
How to use OnTriggerEnter? (JS) 1 Answer
How do I pass through certain colliders but detect all collisions? 1 Answer
Get all child not working? 1 Answer
How to make the bodyParts to follow same places and directions as the player? 0 Answers
Can a object without a rigidbody be triggered by a trigger? 1 Answer