Im trying to develop FPS game where monsters come at me and attack me.
How i create the player(which is 1st person, so a camera)
playerNode = new Node(“Player”);
CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1.5f, 6f, 1);
player = new CharacterControl(capsuleShape, 0.05f);
player.setJumpSpeed(20);
player.setFallSpeed(40);
player.setGravity(40);
playerNode.addControl(player);
player.setPhysicsLocation(new Vector3f(-150, -10, -20));
bulletAppState.getPhysicsSpace().add(player);
rootNode.attachChild(playerNode);
How i create a NPC
Node monster = (Node) assetManager.loadModel(“Models/Oto/Oto.mesh.xml”);
monster.setLocalScale(0.7f);
monster.setLocalTranslation(-120, -20, 0);
monster.setUserData(“Id”, id);
monster.setUserData(“Hp”, 100);
monster.setName(“Monster” + id);
rootNode.attachChild(monster);
control = monster.getControl(AnimControl.class);
control.addListener(this);
channel = control.createChannel();
channel.setAnim(“Walk”);
channel.setLoopMode(LoopMode.Loop);
monster_phys = new CharacterControl(capsuleShape, 0.01f);
// Attach physical properties to model and PhysicsSpace
monster_phys.setJumpSpeed(20f);
monster_phys.setMaxSlope(1.5f);
monster_phys.setPhysicsLocation(new Vector3f(10, 5, 0));
monster.addControl(myCharacter_phys);
bulletAppState.getPhysicsSpace().add(monster_phys);
I know that their cant be any collison but i just want the monsters to walk around normal.
Now here is my question, how am i supposed to make this NPC come to attack me?
I’ve tried all the possible things with monster_phys.setWalkDirection and nothing worked.
I just want the NPC to come to my location.
Can anyone please help me, i’ve searched the whole forum and didnt find the right solution.