≡
Products
▼
Support
▼
Company
▼
Forum
Ambiera Forum
Discussions, Help and Support.
Create a new account
,
Search
, or Login:
Create reply in
BAsic Agressive AI for characters
Posted by:
(you are not logged in)
Enter the missing letter in: "Inte?national"
(you are not logged in)
Text:
[quote][b][/b] wrote: Very useful, thanks i ve added some more functions… checking node health switch between walk and attack animations. // This is a coppercube behavior AI // The following embedded xml is for the editor and describes how the behavior can be edited: // Supported types are: int, float, string, bool, color, vect3d, scenenode, texture, action /* <behavior jsname="behavior_AI" description="Basic AI - AGRESSIVE"> <property name="attack_node" type="scenenode" /> <property name="attack_radius" type="int" default="100" /> <property name="attack_action" type="action" /> <property name="attack_interval" type="int" default="500" /> <property name="step_before_fire" type="int" default="5" /> </behavior> */ behavior_AI = function() { // settings: this.attack_node = this.attack_node; this.attack_radius = this.attack_radius; this.LastTime = null; this.LastPosition = new vector3d(0,0,0); this.stepcounter =0; this.firecounter=0; this.step_before_fire=this.step_before_fire; }; behavior_AI.prototype.onAnimate = function(n, timeMs) { var targetPos = ccbGetSceneNodeProperty(this.attack_node, 'Position'); var currentPos = ccbGetSceneNodeProperty(n, 'Position'); var name=ccbGetSceneNodeProperty(n, 'Name'); var health=ccbGetCopperCubeVariable("(hashtag)+name+".health"); if (health == 0 ) return false;// AI must be died, return.. if ( ( timeMs - this.LastTime) > this.attack_interval ){ var distance = Math.sqrt( Math.pow( parseInt(targetPos.x-currentPos.x) ,2) + Math.pow( parseInt(targetPos.y-currentPos.y) ,2) + Math.pow( parseInt(targetPos.z-currentPos.z) ,2) ); if ( distance < this.attack_radius ){// moving towards attack node.. if (this.firecounter ==0) { ccbAICommand(n, "cancel"); ccbAICommand(n, "moveto", targetPos); this.stepcounter++; } else this.firecounter --; // wait until attack anım ends... } else { // may be random patrol... } if ( this.stepcounter>this.step_before_fire){ // start attack and wait attack anımation ccbAICommand(n, "cancel"); ccbAICommand(n, "attack", this.attack_node); ccbInvokeAction(this.attack_action); this.stepcounter=0; this.firecounter =1; } this.LastTime = timeMs; } return false; }[/quote]
Possible Codes
Feature
Code
Link
[url] www.example.com [/url]
Bold
[b]bold text[/b]
Image
[img]http://www.example.com/image.jpg[/img]
Quote
[quote]quoted text[/quote]
Code
[code]source code[/code]
Emoticons
Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact