Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
Hi Guys, With much effort over the last 4 days I got an alien attack system working which runs inside of a follow path/random patrol scenario and works fine apart from a few bugs: http://lasttrump.net/gamedev.html 1 - I notice in some attacks, the alien will repeat it charging noise in close succession due to the repetition of the code running for 'charge' one after the other - not sure why as when done once its mode gets changed to 'mode_charge' instead of 'mode_follow' and so shouldn't be repeating it like that... 2 - The alien can just be side stepped when charging at you and it keeps running forward - I was thinking it should stop and face you and attack you from there - not sure how to implement that... here is my code: /* <action jsname="action_moveAI_attack" description="Move AI to position & attack"> <property name="ThisNode" type="scenenode" /> <property name="TargetNode" type="scenenode" /> <property name="ChargeRange" type="float" default="70" /> <property name="ChargeAction" type="action" /> <property name="AttackRange" type="float" default="23" /> <property name="AttackAction" type="action" /> <property name="CancelRange" type="float" default="200" /> </action> */ action_moveAI_attack = function() { this.Attacking = false; this.mode = 0; }; // called when the action is executed action_moveAI_attack.prototype.execute = function(currentNode) { var me = this; this.registeredFunction = function() { me.walk(); }; ccbRegisterOnFrameEvent(this.registeredFunction); this.ThisNode = currentNode; } action_moveAI_attack.prototype.walk = function(){ var moveto = ccbGetSceneNodeProperty(this.TargetNode, "Position") ; var mepos = ccbGetSceneNodeProperty(this.ThisNode, "Position"); var tmp = mepos.substract(moveto); var length = tmp.getLength(); var mode_ignore=0; var mode_follow=1; var mode_charge=2; var mode_attack=3; var mode_wait= 4; var mode_die=5; var my_health = "" + ccbGetSceneNodeProperty(this.ThisNode,"Name") + ".health"; if (ccbGetCopperCubeVariable(my_health)<=0) { ccbInvokeAction(this.ActionOnDie); ccbSetSceneNodeProperty(this.ThisNode, 'Animation', 'die'); ccbSetSceneNodeProperty(this.ThisNode, 'Looping', false); } if(length <=this.AttackRange){ ccbInvokeAction(this.AttackAction, this.ThisNode); ccbUnregisterOnFrameEvent(this.registeredFunction); ccbSetCopperCubeVariable("alien1.movementspeed",25); this.mode = mode_wait; print("4. attack"); } else if(length <=this.ChargeRange){ if (this.mode == mode_follow){ ccbInvokeAction(this.ChargeAction, this.ThisNode); this.mode = mode_charge; print("2. charge"); }} else if (length >=this.CancelRange){ ccbUnregisterOnFrameEvent(this.registeredFunction); ccbSetCopperCubeVariable("alien1.movementspeed",15); ccbSetSceneNodeProperty(this.ThisNode,"Animation","walk") ; ccbSetSceneNodeProperty(this.ThisNode, 'Looping', true); this.mode = mode_ignore; print("ignore"); } else { ccbSetCopperCubeVariable("alien1.movementspeed",25); var mvec = moveto.substract(mepos); ccbAICommand(this.ThisNode, "moveto", moveto.add(mvec)); this.mode = mode_follow; print("1. follow"); } } |
||||
|
no-one there to help....sad. anyway I finally worked it out to get the enemy to hunt you down so that you can hardly escape once within attack range...seems to work well enough now. |
||||
|
Robo wrote: no-one there to help....sad. anyway I finally worked it out to get the enemy to hunt you down so that you can hardly escape once within attack range...seems to work well enough now. Please can you tell us how you did this or refer me to a post that sheds more light on it |
||||
|
I have since redone the coding to the above AI code so many times that its quite old topic for me now. Its been a while since I redid my code so might be a while before I look into this again... from memory I had the enemy in its charge cycle at a certain distance from the player to follow the player somewhat so it doesn't fly in a straight line towards the player and not move... |
||||
|
To fix the repeating sound, I use a variable.... IF "charging" = 0, Play sound "charging.wav" Set Variable "charging" = 1 Using this, the sound will only play once (when "charging" = 0). I don't know how you would do this with scripting,; my entire game is made using only visual coding - no scripting. |
|