//----------------------------------------------------------------------------- // Torque Game Builder // Copyright (C) GarageGames.com, Inc. //----------------------------------------------------------------------------- if (!isObject(FaceObjectLRBehavior2)) { %template = new BehaviorTemplate(FaceObjectLRBehavior2); %template.friendlyName = "Face Object Left-to-Right-TEST"; %template.behaviorType = "AI"; %template.description = "Turn the object left or right to face another object"; %template.addBehaviorField(object, "The object to face", object, "", t2dSceneObject); } function FaceObjectLRBehavior2::onBehaviorAdd(%this) { %this.owner.enableUpdateCallback(); } function FaceObjectLRBehavior2::onUpdate(%this) { if (!isObject(%this.object)) return; %objIsOnTheLeft = %this.object.Position.X - %this.owner.Position.X; if (%objIsOnTheLeft > 0) %this.owner.setFlipX(false); else %this.owner.setFlipX(true); }