ambiera logo

Ambiera Forum

Discussions, Help and Support.

folder icon Ambiera Forum > CopperCube > Help with CopperCube
forum topic indicator How to create a basic zombie Ai using the "behaviors & actions" properties?
person icon
icerazor
Registered User
Quote
2023-07-24 23:56:15

Hello, I was wondering how can I make a ENEMY node spot and run after PLAYER node?

I tried to make one by doing the following:

1) Add zombie mesh

2) Player node (zombie) > Behavior= On_Proximity_Do_Something

3) Action= Change_Position_of_Scene_Node


emoji icon_cry It didn't work, so do any else know of a way to set it up?

person icon
Guest
Guest
Quote
2023-07-25 05:34:05

Use the Behavior with Health andAi for your enemy node and give it proper tags and fill the properties, it will automatically spot and chase the player and even attack on him.

person icon
second guest
Guest
Quote
2023-07-29 02:00:45

Sometimes the built in Ai can be spotty and if that doesn't work use this

/*
<behavior jsname="behavior_AI6" description="AI6">
<property name="Player" type="scenenode" default="Camera1" />
<property name="Me" type="scenenode" default="AI" />
<property name="MuvSpeed" type="float" default="0.5" />
<property name="dist1" type="float" default="500.0" />
<property name="dist2" type="float" default="50.0" />
<property name="ActionAttack" type="action" />
</behavior>
*/

var radToDegA = 180.0 / 3.14159265359;

function calculateAngleY(p1, p2) {
pos_o_x=p1.x-p2.x;
pos_o_z=p1.z-p2.z;
angle_towards_target = Math.atan2(pos_o_x, pos_o_z) * radToDegA;
if (angle_towards_target < 0.0)
angle_towards_target += 360.0;
if (angle_towards_target >= 360.0)
angle_towards_target -= 360.0;
return angle_towards_target;
}

function calculateDistance(p1, p2) {
var a = p2.x - p1.x;
var c = p2.z - p1.z;
return Math.sqrt(a * a + c * c);
}

behavior_AI6 = function()
{
this.last_see=null;
}

behavior_AI6.prototype.onAnimate = function(currentNode)
{
var player = ccbGetSceneNodeProperty(this.Player, "Position");
var me = ccbGetSceneNodeProperty(this.Me, "Position");
var can_see_me=ccbGetCollisionPointOfWorldWithLine(player.x,player.y,player.z, me.x, me.y, me.z);
var dist=calculateDistance(player,me);


//I see player and its in range ..muv closer
if(dist>this.dist1 && dist<this.dist2 && can_see_me==null)
{
var ang=calculateAngleY(player, me);
me.x+=Math.sin(ang* (Math.PI / 180))*this.MuvSpeed;
me.z+=Math.cos(ang* (Math.PI / 180))*this.MuvSpeed;

ccbSetSceneNodeProperty(this.Me, "Position", me);
ccbSetSceneNodeProperty(this.Me, "Rotation",new vector3d(0,ang,0) );

this.last_see=player;//save pos wher i saw player.
}


//I dont see player..muv last seen location.
if(can_see_me!=null && this.last_see!=null)
{
player=this.last_see;
dist=calculateDistance(player,me);
var ang=calculateAngleY(player, me);
can_see_pos=ccbGetCollisionPointOfWorldWithLine(player.x,player.y,player.z, me.x, me.y, me.z);
if(dist>1 && can_see_pos==null)
{
me.x+=Math.sin(ang* (Math.PI / 180))*this.MuvSpeed;
me.z+=Math.cos(ang* (Math.PI / 180))*this.MuvSpeed;

ccbSetSceneNodeProperty(this.Me, "Position", me);
ccbSetSceneNodeProperty(this.Me, "Rotation",new vector3d(0,ang,0) );
}
}

//Action on attack..
if(dist<=this.dist1 && can_see_me==null)
{
ccbInvokeAction(this.ActionAttack, this.currentNode);
}

return true;
}


I believe it was made by sven but I Can't find it anymore but it works perfectly

person icon
Guest
Guest
Quote
2023-07-30 06:57:57

How do you use this? Do you need to create a js file?

person icon
second guest
Guest
Quote
2023-08-05 19:14:34

yeah I couldn't upload it to OneDrive so I just copied it you need to make it a js file

person icon
sven
Registered User
Quote
2023-08-05 23:20:32

icerazor wrote:
Hello, I was wondering how can I make a ENEMY node spot and run after PLAYER node?

I tried to make one by doing the following:

1) Add zombie mesh

2) Player node (zombie) > Behavior= On_Proximity_Do_Something

3) Action= Change_Position_of_Scene_Node


emoji icon_cry It didn't work, so do any else know of a way to set it up?



With these action scripts you can make basic AI and much more.. example ccb file included with simple AI and other useful stuff.

https://5v3n.itch.io/coppercube-...


Create reply:










 

  

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


icon_holyicon_cryicon_devilicon_lookicon_grinicon_kissicon_monkeyicon_hmpf
icon_sadicon_happyicon_smileicon_uhicon_blink   






Copyright© Ambiera e.U. all rights reserved.
Contact | Imprint | Products | Privacy Policy | Terms and Conditions |