Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Third-person camera support? #54

Closed
queer opened this issue May 19, 2019 · 3 comments
Closed

Third-person camera support? #54

queer opened this issue May 19, 2019 · 3 comments

Comments

@queer
Copy link

queer commented May 19, 2019

As far as I know, noa doesn't support this, so I tried to implement it myself. You can see what little progress I made on my fork: https://github.com/queer/noa. My solution was basically:

At this point, most everything works correctly execpt for raycasting to get the block the camera is pointing at. There are a few things like camera min/max angles not being exactly correct, but that was less-important than raycasting to me.

After digging into it more, the problem appears to be that Engine.getCameraVector() seemingly ends up being perpendicular to the direction the camera itself is facing in, making Engine.pick() return incorrect results. I tried to fix this by using the camera pitch/yaw (from Engine.rendering.getCameraRotation()) to construct a unit vector that faces in the correct direction, but that didn't produce the correct result either; it just gave me a vector that was still facing in the wrong direction, but with a different perpendicularity relative to the camera's actual direction. The attempts at that can be seen here: queer@43cf935#diff-1fdf421c05c1140f6d71444ea2b27638R397 (including some remnants of probably-misguided attempts at transforming the rotations / unit vector)

At this point I'm pretty lost as to what can be done to implement this correctly. I was wanting to open a PR if I managed to implement this successfully, but it doesn't seem like it's likely to happen.

@fenomas
Copy link
Owner

fenomas commented May 20, 2019

Hey, thanks for looking at the library!

Third person camera can mean a couple of things, but did you see noa.rendering.zoomDistance? In all my demos scrolling the mousewheel zooms the camera back by changing that property.

The way it currently works is, there's an empty mesh called noa.rendering._cameraHolder that stays pinned to the player's view location and rotates as the player moves their view. Then the actual camera is a child of that mesh, and when you change the zoomDistance the camera moves back and forth in the camera holder mesh's local coordinates, so in world coords it winds up projected to a point behind the player.

But it's meant to be an optional default implementation - a game with particular needs can in principle make a new camera and have it move however, and tell Babylon to render with that one instead of the default one. I haven't done this personally, so there might be wrinkles though.

Let me know if that's what you're looking for..

@queer
Copy link
Author

queer commented May 20, 2019

Oh my goodness, I can't believe I didn't figure this out. Yes, this is exactly what I was wanting! Thank you so much! ❤️

@queer queer closed this as completed May 20, 2019
@fenomas
Copy link
Owner

fenomas commented May 20, 2019

Ah good... the property could probably be better named. BTW there's also a camera zoom speed property, for how fast the camera tweens to the desired zoom level. But the default behavior is that the library also raycasts backwards from the player's head each frame looking for obstructions, and limits the zoom level if it encounters solid voxels.

Hope that helps, thanks for trying things out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants