problem with enemy AI
by Phil Head · in Torque Game Builder · 04/26/2010 (4:36 am) · 1 replies
me and my friend are making a platformer game which is kind of similar to the original donkey kong game, we wanted to make the AI follow the player originally but were unable to program it. so we decided to make the enemy climb the ladder whenever it feels like by a random number and also getting off at certain points of the ladder. The problem is, is that the schedule in the code is not being executed in the code and therefore creating problems for the enemy for example getting stuck on a block. (deadlineClass is the enemy)
here is the code:
here is the code:
function ladderMiddle::onEnter(%this, %object)
{
if(%object.class $= "deadlineClass")
{
%random = getRandom(0,1);
if(%object.getLinearVelocityY() > 0) //climbing up or down the ladder
{
if(%random == 0) //goes left
{
%this.schedule(2000,onEnter);
%object.setLinearVelocityX(-10);
%object.setLinearVelocityY(0);
} else if(%random == 1) //goes right
{
%this.schedule(2000,onEnter);
%object.setLinearVelocityX(10);
%object.setLinearVelocityY(0);
}
} else if (%object.getLinearVelocityX() != 0) //walking into the ladder
{
if(%random == 0) //goes up
{
%object.setLinearVelocityX(0);
%object.setLinearVelocityY(-10);
} else if(%random == 1) //goes down
{
%object.setLinearVelocityX(0);
%object.setLinearVelocityY(10);
}
}
}
}
Torque Owner Kevin James
%this.someID = %this.schedule(2000, "onEnter", %object);
1. You should always assign your schedules to an ID
2. The function should be in quotes
3. You need to pass in the variable that OnEnter is looking for.