I'd like to make my object chase another one of my objects.

Hello everyone,

I have just tried to do just the one function: There is one target object. I am moving the object in runtime.

There’s another object which should chase the aforementioned object.

It should, let us say colourfully, “catch” the target object if the objects touch. If caught, the target object, she will be completely destroyed with a dramatic flourish. That’s the concept in a nutshell.

But now … as so often in life … the problem

My problem, the hunted object is moving but the hunter-object is not moving correctly.

Can anyone help me do this? Thanks!

You should post your script - how could we help without seeing it? Anyway, the basic idea is: calculate the target direction and move towards it - something like this:

var target: Transform; // drag the target here, or "GameObject.Find" it at Start
var chaseSpeed: float = 5;

function Update(){
  var dir = target.position - transform.position; // get the target direction
  var dir.y = 0; // keep it strictly horizontal
  var vel = dir.normalized * chaseSpeed; // calculate the velocity vector
  // the way you will actually move depends on your character's nature:
  //- If it's a simple object (no Rigidbody, no CharacterController):
  transform.Translate(vel * Time.deltaTime, Space.World);
  //- If it's a CharacterController (SimpleMove includes gravity automatically):
  GetComponent(CharacterController).SimpleMove(vel);
  //- If it's a Rigidbody (not recommended: rigidbodies are too wild!):
  vel.y = rigidbody.velocity.y; // keep the rigidbody gravity
  rigidbody.velocity = vel;
}