Game Development Community

moveTo Function

by John Roberts · in Torque Game Builder · 05/18/2010 (11:44 pm) · 3 replies

Hello all.

I am attempting to create an AI Behavior for a small game I'm working on, in the science-fiction vein. I'd like to create two computer-controlled objects, spaceships, that will follow my player at a distance, mimicking his movements.

I have attempted to do this using the moveTo function in Torque, but have not had great success.

This is as far as I have gotten:


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

%template.friendlyName = "Wingman - FormUp";
%template.behaviorType = "AI";
%template.description = "The wingman will take up position behind the Player.";

%template.addBehaviorField(Target, "The object to move toward.", object, "", t2dSceneObject);
%template.addBehaviorField(OffsetY, "Distance behind Object on the y-axis (world units).", integer, 15);
%template.addBehaviorField(OffsetX, "Distance behind Object on the x-axis (world units).", integer, 15);
%template.addBehaviorField(TrackFreq, "Frequency of tracking updates (seconds).", float, 1);
%template.addBehaviorField(Speed, "Speed at which to move (world units per second).", float, 20.0);
}


function FormUp::onAddToScene(%this)
{
echo("Wingman added to scene.");

%this.owner.enableUpdateCallback();
%this.schedule(%this.TrackFreq, "Move");
}


function FormUp::Move(%this)
{
echo("Forming up.");

%this.PosY = %this.OffsetY + %this.Target.getPositionY();
%this.PosX = %this.OffsetX + %this.Target.getPositionX();

%this.owner.moveTo("%this.PosX %this.PosY", %this.Speed, 1, 1, 1, 0.1);
}


It seems that the moveTo function will not accept any variable I attempt to pass into it for the X/Y coordinates, only regular numbers.

Can anyone help an aspiring game designer with a solution?

About the author

An aspiring game designer with little programming experience - looking to live and learn.

Recent Threads

  • bindCmd & getWord

  • #1
    05/19/2010 (12:25 am)
    try changing this

    "%this.PosX %this.PosY"

    to this

    %this.PosX SPC %this.PosY

    without the quotes and use "SPC" instead
    #2
    05/19/2010 (6:55 pm)
    Thank you!

    If you could explain, what precisely does "SPC" do? What does it stand for?
    #3
    05/21/2010 (2:12 pm)
    SPC is the reserved character for adding a space in a string.

    If I wanted to say "Hello World", I could do echo("Hello World"); or I could also do echo("Hello" SPC "World); They would yield the same result.

    Anything inside of quotes will be sent as a string literal.

    %a=1;
    echo(%a); // Would echo 1
    echo("%a"); // Would echo %a