Jump to content

Get Left Vector of Target Object in relation to active Camera


Pryme8
 Share

Recommended Posts

 

So I know how to get the forward vector:

var forward = scene.activeCamera.position.subtract(gameSettings.playerObject.position).normalize();
forward.y = 0;

but how does one go about getting the left vector?
I can apply an impulse playerObject.applyImpulse(forward.scale(-0.05), playerObject.position);   

and effectively push the object away from the camera, but how would I "push" from the left of the object or the right of the object in relation to the camera?


***EDIT***

I thought about it and it dawned on me... cross the up vector of the camera with its direction...
 

var forward = scene.activeCamera.position.subtract(gameSettings.playerObject.position).normalize();
				
var right = BABYLON.Vector3.Cross(forward, scene.activeCamera.upVector).normalize();
right.y = 0;

 

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...