Jump to content

FreeCamera 'Look At'


stormwarestudios
 Share

Recommended Posts

Hello,

I've been adding features to my game, and came across a weirdness that I don't know how to explain!

I've created the basis for my question here. There are a number of objects in the game scene, and I want the player to be able to choose one to look at. I am using the FreeCamera, since it suits my purposes.

After adapting the TargetCamera.setTarget function to return the rotation vector of a camera without setting its target explicitly, I can now create an easing animation which gracefully orients the camera in that direction. The link above demonstrates this working in a loop which starts one animation, then on completion, selects a new random target, and starts the animation all over again.

The problem is Line 45:

camera.rotation.z = 0;

Without this line, at the end of the animation, the camera.rotation (normally a Vector3 with x,y,z) becomes a Vector2 with x,y. This causes the screen to go black after the last frame of animation.

Now, my two questions:

1. Why? :) It seems to me that dropping the last part of a Vector3 at the end of an animation is a bug, but my inexperience with BabylonJS makes me think there is probably a better explanation.

2. Is there a better way that I could animate a FreeCamera's orientation?

Thanks for your time, and if this solves a problem for anyone, please enjoy the code :)

Cheers,

- Peter

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