Game Development Community

adjusting code

by rennie moffat · in General Discussion · 06/23/2009 (11:20 am) · 1 replies

hi, this code is for an AI. it tells an object to move towards another object.


What I am wondering is how does this object know what object to move towards?
I am not sure where to plug it in in the code.



if (!isObject(MoveTowardBehavior))
{
%template = new BehaviorTemplate(MoveTowardBehavior);

%template.friendlyName = "Move Toward";
%template.behaviorType = "AI";
%template.description = "Set the object to move toward another object";

%template.addBehaviorField(object, "The object to move toward", object, "", t2dSceneObject);
%template.addBehaviorField(speed, "The speed to move toward the object at (world units per second)", float, 2.0);
}

function MoveTowardBehavior::onAddToScene(%this)
{
%this.owner.enableUpdateCallback();
}

function MoveTowardBehavior::onUpdate(%this)
{
if (!isObject(%this.object))
return;

%this.owner.moveTo(%this.object.position, %this.speed);
}

About the author

My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.


#1
06/23/2009 (11:40 am)
SoI just added this in as a behavior.
the interface asks me to select an object (A) (for object(B) to move to) I have two objects, (sprites) on screen, one has this behavior, I would presume the other image would be an option for selection, but nothing.I have no options from the drop down menu.


:?