TomaszFurca Posted May 19, 2017 Share Posted May 19, 2017 Hi, i want create visibility area of my enemies, when he saw any player he go to player. I choose raycast, is good choice? But i have problem with raycast arround enemy object, how can i do that? Tom Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 29, 2017 Share Posted May 29, 2017 Raycast is too precise as it is just a ray I would suggest some kind of sphere vs. cylinder collision (the sphere represents the enemy and the cylinder the field of view of the player) Wingnut 1 Quote Link to comment Share on other sites More sharing options...
TomaszFurca Posted May 29, 2017 Author Share Posted May 29, 2017 Good tip, thanks - when i create something i will put this in this topic. Wingnut 1 Quote Link to comment Share on other sites More sharing options...
TomaszFurca Posted May 29, 2017 Author Share Posted May 29, 2017 Its done and works perfect: let mainMesh = BABYLON.MeshBuilder.CreateBox('enemy', { width: 0.5, size: 0.7}, game.scene); mainMesh.position = new BABYLON.Vector3(Game.randomNumber(3,-10), 1.1, Game.randomNumber(-10,-16)); mainMesh.visibility = false; mainMesh.physicsImpostor = new BABYLON.PhysicsImpostor(mainMesh, BABYLON.PhysicsImpostor.BoxImpostor, { mass:1, friction:0.01, restitution:0.2}, game.scene); let attackArea = BABYLON.MeshBuilder.CreateBox('enemy_attackArea', { width: 1.7, height: 0.1, size: 1.7}, game.scene); attackArea.parent = mainMesh; attackArea.visibility = false; let visivilityArea = BABYLON.MeshBuilder.CreateBox('enemy_visivilityArea', { width: 12, height: 0.1, size: 12}, game.scene); visivilityArea.parent = mainMesh; visivilityArea.visibility = false; and afterRender in variable to unregister, after dispose object. this.afterRender = function() { if(game.player) { if (self.visibilityArea.intersectsMesh(game.player.character.mesh, false)) { self.character.mesh.lookAt(game.player.character.mesh.position); var playerMesh = game.player.character.mesh.getChildMeshes()[0]; if(self.attackArea.intersectsMesh(playerMesh, false)) { self.character.runAnimationHit(); if (self.character.items.weapon.intersectsMesh(game.player.character.mesh, false)) { playerMesh.material.emissiveColor = new BABYLON.Color4(1, 0, 0, 1); var value = game.guiElements.hpBar.getValue(); game.guiElements.hpBar.updateValue(value - 0.2); if(value-0.1 < 0) { window.location.reload(); } } else { playerMesh.material.emissiveColor = new BABYLON.Color4(0, 0, 0, 0); } } else { var velocity = BABYLON.Vector3.TransformNormal(new BABYLON.Vector3(0, 0, -0.041), self.character.mesh.computeWorldMatrix()); self.character.mesh.moveWithCollisions(velocity); self.character.runAnimationWalk(); } } } }; game.scene.registerAfterRender(this.afterRender); Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted June 6, 2017 Share Posted June 6, 2017 Excellent solve, thx for sharing. I found another post about shooting a ray from wandering enemy -> player, and if it hits a wall, then enemy cannot "see" player. Some links to pathfinding systems are there, too. http://www.html5gamedevs.com/topic/27889-solved-solutions-for-virtual-joystick-camera/?do=findComment&comment=160588 Not sure if you need this or not. Might be fun feature to add to game. Be sure to mark this thread as [solved] if you wish (edit 1st post, change title). But if you are still waiting for more replies, no need to mark as solved, of course. I just wanted to pass-on something that might interest you. Be well. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.