Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Announcements and Showcase
npc enemy follow and attack scripts

o139
Registered User
Quote
2024-04-02 18:04:25

Here is a 2 seperate scripts for enemy follow and enemy attack in case anyone needs it the scripts are free to use and modify

edit: i should have mentioned that these scripts also work for in game clones

put this code on enemy for examble "every 1000ms execute javascript" and it will attack player when he is close

note you will have to change the text wiz to your player note name

note. both the player and npc enemy need to have Actor behavior


//made by o139

note=ccbGetCurrentNode();
var pos1 = ccbGetSceneNodeProperty(note, "Position");

child = ccbGetSceneNodeFromName("wiz");
var pos2 = ccbGetSceneNodeProperty(child, "Position");


var distance = pos1.substract(pos2).getLength();

if(distance<=30){

pos = ccbGetSceneNodeProperty(note, "Position");
ccbSetSceneNodeProperty(note, "Position",pos.x,pos.y+5,pos.z);

hp=ccbGetCopperCubeVariable("wiz.health" );

hp=hp-10;

ccbSetCopperCubeVariable("wiz.health",hp )
ccbAICommand(note, "cancel");
}


use this with the this enemy follow script
the enemy will start moving towards enemy when he is x a way from player

put it on enemy "every 1ms , execute javascript

note you will need to change the text player to your player name and change the distance to your liking.


//made by o139

dragon = ccbGetCurrentNode();
pos1 = ccbGetSceneNodeProperty(dragon, "Position");

player = ccbGetSceneNodeFromName("player");
pos2= ccbGetSceneNodeProperty(player, "Position");

distance = pos1.substract(pos2).getLength();

if(distance<=60){
ccbAICommand(dragon, "moveto", new vector3d(pos2.x, pos2.y, pos2.z));

}


edit i changed the distance variable it was wrong should be <


andgameplay
Registered User
Quote
2024-04-03 01:42:12

Great, thanks for the scripts!


writer
Guest
Quote
2024-04-03 17:31:01

Great, thanks!


o139
Registered User
Quote
2024-04-03 18:05:28

welcome!


Create reply:


Posted by: (you are not logged in)


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