Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
If I need to make an AI, how do I check if I hit it?

dekon_17
Registered User
Quote
2022-03-28 17:21:10

So, I continued creating my WebGL game. And because the enemies there are infected, I started creating my own AI, since the standart AI of CopperCube is not suited well for them. I want to make them follow player always (standart AI will move from one point to another one, and if player moves, then AI will have to reach its destination point, realise that the player left the area and then try to get close to him again). The problem I stumbled in is that I don't exactly know how to register any hits on it with standart "Collide when moved" behavior. Do anyone know something about that? Like, how to make this?


coa
Registered User
Quote
2022-03-28 17:35:13

are you talking about making the AI always follow player and attack when close if you are you could use follow node script and (on proximity on income) of player stop and start to attack you if player moves the AI (on proximity on exit) start to follow again


dekon_17
Registered User
Quote
2022-03-28 18:42:41

Can't say that I really understood you, coa, but I already made a bit different choise. I think that I can use "ccbAICommand" to do the things I want to. Still, maybe your method could be good as well.


dekon_17
Registered User
Quote
2022-03-28 18:57:25

Okay, I was able to make enemy follow player everytime, but the attack doesn't work, I guess. I tried to do this in the behavior:
var posT = ccbGetSceneNodeProperty (this.ToAttack, "Position");
var pos = ccbGetSceneNodeProperty (node, "Position");
var vector = new vector3d (posT.x - pos.x, 0, posT.z - pos.z);

var dist = vector.getLength();

if (dist <= 10)
{
ccbAICommand (node, "attack", this.ToAttack);
}
else
{
ccbAICommand (node, "moveto", new vector3d (posT.x, pos.y, posT.z));
};

My only idea is that enemy can't hurt me because he tries to attack every frame, so, he can't land a single hit in this short time. Am I... Right?


sulbcon
Registered User
Quote
2022-04-02 23:21:39

Yes you are right.
My solution might feel a bit weird but you can give it a try.
1.) Make an action that will make the scenenode attack your character.
2.) Attach a behavior making the scenenode call an action in a regular time interval.
3.) In the script you wrote above, instead of calling the attack command make it set a coppercube variable to 1, and in the else along with what you put there set the variable back to 0.
4.) Then in the behavior attached in no. 2. ad a condition action(i.e if variable = this)
Saying if the variable created above is equal to 1, then call the attack action created above
I hope this works


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Interna?ional" (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