Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
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 |
||||
|
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. |
||||
|
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 |
||||
|
How do you use this? Do you need to create a js file? |
||||
|
yeah I couldn't upload it to OneDrive so I just copied it you need to make it a js file |
||||
|
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 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-... |
||||
|
|