rakesh Posted February 22, 2017 Share Posted February 22, 2017 Hello, I just want to create a zombie which follows the player. I have seen the tutorials of unity 3d but failed to convert it into BABYLON JS form.( I don't know the how to convert Quaterian.LookRotation in unity 3d can be used in babylon js) Can someone please give me an idea how to achieve this. Quote Link to comment Share on other sites More sharing options...
Temechon Posted February 22, 2017 Share Posted February 22, 2017 It's typescript but it work : private _update() { // get the direction vector toward the player var colliderPosition = this._game.player.position; var dir = colliderPosition.subtract(this.position); dir.normalize(); dir.y = 0; // get the next position of the zombie var dest = dir.scale(0.015).scale(this.speed*2); // the zombie is a mesh this.look(this._game.player.position); this.moveWithCollisions(dest); // or zombie.position.addInPlace(dest) } /** Make this mesh look at the given position (only along the y axis) */ public look (pos) { var dv = pos.subtract(this.position); var yaw = -Math.atan2(dv.z, dv.x) - Math.PI / 2; this.rotationQuaternion = BABYLON.Quaternion.RotationYawPitchRoll(yaw, 0, 0); } my 'update' function is called with scene.registerBeforeRender(update); FYI, the whole source code is here: https://github.com/Temechon/infection, and the project is currently abandoned. adam, xtreemze and Dad72 3 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.