Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Help with CopperCube
How to freeze the script AI Agressive?

andgameplay
Registered User
Quote
2023-09-16 23:17:02

Hi guys, I'm using the AI Agressive behavior for the enemy, but when the enemy die, he do the "die animation" but come back alive and continues shooting!

The enemy need to die and stay died!

Any idea?

I think the script Ai agressive continues working and shooting when the enemy is died.

Thanks!


okeoke
Registered User
Quote
2023-09-17 05:21:11

This usually happens to me if call ccbAICommand on a dead enemy.

To prevent this I do the following:
1. Built-in actor behavior has "on death" action property - add there an action which reads enemy node name, and then sets a variable with name like enemyNodeName + '_is_dead'. Set its value to 1 (I believe, booleans do not work with ccbSetCopperCubeVariable);
const enemyNodeName = ccbGetSceneNodeProperty(node, 'Name');
ccbSetCopperCubeVariable(enemyNodeName + '_is_dead', 1);

2. Add ccbGetCopperCubeVariable(enemyNodeName + '_is_dead') check to top of your custom AI behavior onAnimate function, which interrupts onAnimate execution in case it's set to 1:
behavior_YourAI.prototype.onAnimate = function (node, timeMs) {
const enemyNodeName = ccbGetSceneNodeProperty(node, 'Name');
if (ccbGetCopperCubeVariable(enemyNodeName + '_is_dead') === 1) return;
...

This also can happen in case you have some scheduled actions like doLater or setTimeout or something similar to control the AI. You need to add similar checks to these too.


andgameplay
Registered User
Quote
2023-09-17 19:58:10

Thanks okeoke, I aprecciate your help, I will try!


Monks
Guest
Quote
2023-12-07 08:57:07

Okeoke, can you please elaborate on how you corrected the enemy ai you mentioned above, I don't really understand much of coding but I really need to do this, if possible provide a ccb, Thanks


okeoke
Registered User
Quote
2023-12-07 09:12:36

I think I can try. Can you share ccb or tell how your enemies are set up?


Monks
Guest
Quote
2023-12-08 13:58:15

Oh yeah, sorry for late reply, actually my enemies are being cloned after a number of enemies are killed, and the process keeps going like that, is there any info you want me to provide on this


okeoke
Registered User
Quote
2023-12-08 14:17:50

I don't think cloning could cause that issue. Are you using some custom behavior or regular actor script? Also do you clone from a node which doesn't change over time, i.e. it's not active in game. Could it be that you're cloning already dead enemy? Also do you set a unique name for each enemy?


Monks
Guest
Quote
2023-12-08 15:09:19

I have the same problem as andgameplay but I only wish you further explain your approach to me


okeoke
Registered User
Quote
2023-12-08 15:29:02

Ok, I believe this is something that happens in case you execute ccbAICommand function on enemy which is already dead. It seems like in this case command is executed no matter if enemy is dead or not.
The idea is to prevent ccbAICommand from being executed, so you need the script to stop before it reaches ccbAICommand line.
For that you on as enemy dies you set enemyName + "_isDead" variable to 1. Inside enemy script you check for enemyName + "_isDead" variable every time it is executed. If it's equal to 1, you stop execution by calling return.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Inter?ational" (you are not logged in)


Text:

 

  

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