Please help. I’m looking for a simple script (java) to use to make an enemy follow me. :evil: ——> :shock: Simple please. Thanks.
umm that is not a simple script. animations of walking, getting the position of the player making sure the enemy is always a set distance away unless the player walks toward the enemy, etc. you can always use http://angryant.com/path.html for the enemy to go along a path that the user takes (by no other choice only one way to go for the user and make the enemy go on the path)
Hi, here is a very simple function to make an enemy follow the player or anything else.
Hope it helps
Juan
function Follow(enemyTarget : Transform)
{
while(true)
{
if(Vector3.Distance(transform.position, enemyTarget.position) < minimunDistance)
{
var direction = enemyTarget.position - transform.position;
transform.rotation = Quaternion.Slerp(transform.rotation,Quaternion.LookRotation(direction), rotationSpeed * Time.deltaTime);
transform.eulerAngles = Vector3(0,transform.eulerAngles.y,0);
var forward = transform.TransformDirection(Vector3.forward);
direction = forward * walkingSpeed;
GetComponent(CharacterController).SimpleMove(direction);
animation.Play("myWalkAnimation");
}
yield;
}
}
What kind of code?
That kind is javascript because if code has function in it.
Or slap the smoothLookAt script on your enemy(Component menu>Camera Control), and a constant force component (Component>Physics>ConstantForce)with +Z local force. rigidBody also required.
HTH
AC
That’s what I ended up doing.