Game Development Community

AI follow

by Richard Gillis · in Torque X 2D · 12/08/2007 (9:17 am) · 2 replies

Can someone please explane to me how you would have a sprite follow or go to a certain location that a target sprite or object is?
Also if the target changes location it will be able to follow to that location.

Thanks in advance.

About the author

Recent Threads


#1
12/08/2007 (11:32 am)
You will need to create a component to do this. The _OnRegister() method needs to call AddTickCalback() request tick processing. The component needs to set a target scene object field. Then, you need to have a ProcessTick() method to perform the work. For example:

public void ProcessTick(Move move, float elapsed)
{
// determine angle to point to
float angle = T2DVectorUtil.AngleFromTarget(_sceneObject.Position,
_TargetObject.Position);
 
// set the rotation
_sceneObject.Rotation = angle;
 
// move towards obejct
_sceneObject.Physics.Velocity =
T2DVectorUtil.VelocityFromTarget(_sceneObject.Position,
_TargetObject.Position, _speed);
 
return;
}

This is not a full code listing, but you can start with the MovementComponent as a reference.

John K.
#2
12/08/2007 (1:24 pm)
Thanks John,
This is what I was looking for.