Sign in to follow this  
Temptation

Yet another camera question

Recommended Posts

Hello people, just got new to gamedev in general, read a lot here from babylon js forum and learned a lot of new things. 

But I got stuck and wasted almost 4 hours to find out a thing here but just cant.

So my only option is to ask here

I need to make Third person camera, and i got it working. Current implementation is, that I move my "player" regarding absolute location

           UP
LEFT          RIGHT
        DOWN

And the camera forward direction is not taken in consideration.

But what I need Is actually move the player forward regarding the camera forward vector.

Can someone please at least give me the solution how to find camera FW vector ?

Share this post


Link to post
Share on other sites

Oh yeah it worked, thanks

As i didnt find a precise answer on my question, Ill make a post here describing :
 

How to rotate a mesh based on camera forward vector.

First we need to find out camera forward vector:
 

 var forwardVector = BABYLON.Vector3.Normalize(this.mesh.position.subtract(data.scene.activeCamera.position));

And then we need to find the rotation angle : 
 

 var angle = Math.atan2(forwardVector.x, forwardVector.z)

 //And then rotate by Y axes

 this.mesh.rotation = new BABYLON.Vector3(0, angle, 0);;


Thanks! Great forum, learned a lot in 2 days!

Share this post


Link to post
Share on other sites

Hi Temptation... welcome aboard.  Or should I say... "welcome a billboard"? 

http://playground.babylonjs.com/#QKQHS#372

(line 56 - billboardMode... options available for X, Y, Z, or ALL)

Your thing is in lines 63-65 (temporarily deactivated).  Another fun thing is at line 68.

BJS has lots of cool things to play-with, and lots of cool people.  You seem to be one, too.  Good to have you with us!  PARTY!!!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.