02:37 PM 18/03/2023
I am making a game called Crossfire it is simmilar to trench games but instead im using Enemy AI to attack the trench but I do not know on how to make one. Perhaps somebody can tell me? Thanks.
02:19 PM 28/03/2023
It's not really an "AI" but I figured this might help.
let damage = 10; //Amount of damage you want the enemy to deal
let outfit = new Outfit(); //An object to set the appearance of a bot
outfit.body("#FF0000");
outfit.rightLeg("#FFFF00");
outfit.leftLeg("#FFFF00");
let enemy = new Bot("Enemy"); //Creating the Bot object
enemy.setOutfit(outfit);
Game.newBot(enemy); //Adding the bot into the world
enemy.setInterval(() => { //This is self explanatory
let player = enemy.findClosestPlayer(70); //Find the closest player with a radius of 70 studs
if (!player) {return;}
enemy.moveTowardsPlayer(player, 12);
enemy.touching((plr) => {
plr.setHealth(plr.health - damage);
});
}, 5000); //Do this every 5000 milliseconds (5 seconds)
This is slightly based of a part of the code I'm using to create my game. I haven't teste it out yet, so let me know if it works.
let damage = 10; //Amount of damage you want the enemy to deal
let outfit = new Outfit(); //An object to set the appearance of a bot
outfit.body("#FF0000");
outfit.rightLeg("#FFFF00");
outfit.leftLeg("#FFFF00");
let enemy = new Bot("Enemy"); //Creating the Bot object
enemy.setOutfit(outfit);
Game.newBot(enemy); //Adding the bot into the world
enemy.setInterval(() => { //This is self explanatory
let player = enemy.findClosestPlayer(70); //Find the closest player with a radius of 70 studs
if (!player) {return;}
enemy.moveTowardsPlayer(player, 12);
enemy.touching((plr) => {
plr.setHealth(plr.health - damage);
});
}, 5000); //Do this every 5000 milliseconds (5 seconds)
This is slightly based of a part of the code I'm using to create my game. I haven't teste it out yet, so let me know if it works.
07:10 PM 28/03/2023
Quote from havoq , 02:19 PM 28/03/2023you dont have to make the outfit like that, the outfit functions return the outfit object, so you can chain them
It's not really an "AI" but I figured this might help.
let damage = 10; //Amount of damage you want the enemy to deal
let outfit = new Outfit(); //An object to set the appearance of a bot
outfit.body("#FF0000");
outfit.rightLeg("#FFFF00");
outfit.leftLeg("#FFFF00");
let enemy = new Bot("Enemy"); //Creating the Bot object
enemy.setOutfit(outfit);
Game.newBot(enemy); //Adding the bot into the world
enemy.setInterval(() => { //This is self explanatory
let player = enemy.findClosestPlayer(70); //Find the closest player with a radius of 70 studs
if (!player) {return;}
enemy.moveTowardsPlayer(player, 12);
enemy.touching((plr) => {
plr.setHealth(plr.health - damage);
});
}, 5000); //Do this every 5000 milliseconds (5 seconds)
This is slightly based of a part of the code I'm using to create my game. I haven't teste it out yet, so let me know if it works.
let outfit = new Outfit()
.body("#FF0000");
outfit.rightLeg("#FFFF00");
outfit.leftLeg("#FFFF00");
12:45 PM 29/03/2023
Quote from MixaMega , 07:10 PM 28/03/2023Thanks for this, I didn't know that those functions returned the object itself.Quote from havoq , 02:19 PM 28/03/2023
It's not really an "AI" but I figured this might help.
let damage = 10; //Amount of damage you want the enemy to deal
let outfit = new Outfit(); //An object to set the appearance of a bot
outfit.body("#FF0000");
outfit.rightLeg("#FFFF00");
outfit.leftLeg("#FFFF00");
let enemy = new Bot("Enemy"); //Creating the Bot object
enemy.setOutfit(outfit);
Game.newBot(enemy); //Adding the bot into the world
enemy.setInterval(() => { //This is self explanatory
let player = enemy.findClosestPlayer(70); //Find the closest player with a radius of 70 studs
if (!player) {return;}
enemy.moveTowardsPlayer(player, 12);
enemy.touching((plr) => {
plr.setHealth(plr.health - damage);
});
}, 5000); //Do this every 5000 milliseconds (5 seconds)
This is slightly based of a part of the code I'm using to create my game. I haven't teste it out yet, so let me know if it works.
you dont have to make the outfit like that, the outfit functions return the outfit object, so you can chain them
let outfit = new Outfit()
.body("#FF0000");
outfit.rightLeg("#FFFF00");
outfit.leftLeg("#FFFF00");