Jump to content

Artificial Intelligence like zombie


rakesh
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...