Three.js 3rd person camera - camera

I'm trying to create a 3rd person camera view in three.js
I'm using the THREE.FirstPersonControls(); on my camera. Then setting the rotation and positions of my "player" objects to be the same as the camera with some offsets.
This does not seem to work.
What i'm more wondering is if I should be adding my FirstPersonControls to the camera and then rendering the "player" infront of it. Or adding the controls to the player then making the camera always point at the back of the player?
EDIT:
I've tried setting the player object to be a sub object of the camera using camera.add(player);
but moving the camera around is not moving the player. I thought adding an child element would mean they move together?
EDIT 2:
I took another approach of adding both the camera and the player to a group then adding my 1st person controls to that group... Now both the camera and the player do get rendered. But it's completely thrown off how the first person controls worked. (e.g. looking down goes left etc etc)
Thanks for any help,
James

First of all, the Controls were designed to be controlling a camera, and not an object. And since by default, objects look "up" the z-axis, and cameras look "down" the z-axis, it is unlikely that the Controls will work as expected when applied to something other than a camera.
Secondly, the Controls are part of the examples, and not the library, so they are not officially supported. You are free to hack away at them.
One way to achieve what you want is to make the camera a child of your player. Something like this:
player.add( camera );
camera.position.set( 0, 50, 100 );
You may, in your render loop, need to set:
camera.lookAt( player.position );
Then you want to control the player with the mouse or keyboard. Your best bet is to write your own controller to do that. There are plenty of examples on the net.

Related

How would I hide an object from a specific camera in Godot 3D?

I'm working on a multiplayer horror game in Godot and I want to make it so you can't see your own body but others can. I heard about culling masks for this but I have no idea how they work and if what I'm trying to achieve is possible using them. The body is a Skeleton node and others should be able to see it but my camera (a sibling of the skeleton node) shouldn't be able to. Could someone explain how I might be able to do this?
The Skeleton is not visible. However, you must have some children VisualInstances (usually MeshInstance) which are actually visible.
In the usual setup, you have a Skeleton node, with multiple MeshInstance as children, which also have their skeleton property set to the Skeleton node.
I don't know how you are setting up your multiplayer, but if it is not split-screen you probably can swap or remove the player character but not those of the other players. If removing the Skeleton is not viable, you should still be able to remove or hide its children VisualInstances.
Anyway, if you do need to setup multiple cameras, you can se the layers on the MeshInstance (or whatever VisualInstance you are using) and the cull_mask on the Camera. If they overlap (they have common bit flags) then the Camera will render that MeshInstance, otherwise it wont.
See also Hide an object for a specific camera.

How to make the Camera have collision detection Physi.js First Person Shooter

Project Premise
The idea for my THREE.js game is the have the player navigate though a maze of objects and reach an exit. I need collision detection not just for cubes and spheres, but also models imported from Blender. I thought about using RayCasting but I decided to go with Physi.js.
The Problem
,The idea is to give the camera a "body" so that the player can't pass though wall or other objects like they can when they are just a camera object. However, My "player" object seems to loses all of its Physi.js attributes as soon as I give it THREE.PointerLockControls(player). What I'm doing is creating a Physijs.BoxMesh, the player, and adding the camera to that. After that I pass the "player" object to my setupControls() function.
var geometry = new THREE.BoxGeometry( 500, 500, 500 );
var material = new THREE.MeshPhongMaterial( {color: 0x0000FF} );
player = new Physijs.BoxMesh(geometry, material, 1, {restitution: .9, friction: .1});
scene.add(camera);
scene.add(player);
player.add(camera);
//give player control of THIS mesh.
setupControls(player);
The Controls work as expected, I can control the player mesh with the camera stuck to it creating an FPS view, but I when I do this I can still move though walls and other objects. I've even moved the camera back on the Z position to confirm whats going on and I can see that the player mesh is just passing though objects instead of being hindered or knocking them over.
Solutions?
If I remove setupControls(player), then the Physi.js physics begin to work on the player mesh! It will fall from gravity, bounces around and everything. It looks really cool, but now I can't control it! It seems like I can only have one or the other lol. So does anyone know what I could do to solve this problem? Is what I'm preposing even possible? I'm new to THREE.js so any input is much appreciated!

Unity2d; How to raise(lift) camera during game mode at a fixed y axis minimum

I may be making this harder than what it really is, but I am also pretty new to developing games. Currently I am making a practice scene to get back used to the unity engine as I have not had time to use it since last summer. My issue is that I can not figure out how to lift the camera in game mode. Notice my photo below, and how much of the "underground" is showing. I want to raise the camera to keep it at the very least a specific y axis value, so that I can make less of the ground visible, and more of the background visible. If I am over complicating this, please also let me know. Thank you
If main camera is still then just lift the camera in scene view you can see changes in game view.
Or if camera moves with respect to player then you have to use a script and attach it to camera and get a reference of player transform in the script and according to the player position change position of the camera. Add an offset value in y component of the camera.

Is there a way I can let the camera zoom but not rotate?

Is there a way I can let the SceneKit's camera zoom but not rotate? And how can I delimitate the maximum and minimum zoom the user can do with the camera?
It depends what you mean by zoom – if you mean to do the same thing as 'zooming' a camera lens, you want to modify the yFov and xFov (field of view) attributes of the SCNCamera object. The camera stays in the exact same location, but changes its field of view like a zoom lens.
I cannot see how you can rotate the camera while zooming it – I’d need to see more context of where you’re using the camera. If you don’t touch the SCNNode the camera is attached to, you can’t possibly rotate it.
You're talking about user camera movement with allowsCameraControl, right? I don't think that's really meant to be the basis for a sophisticated user camera movement scheme, more of a simple debugging aid. If you really want fine control over how the user can move the camera, you're best served by creating your own camera node and moving it / changing its properties in response to whatever user input you want to handle (gesture recognizers, game controllers, etc).
I suppose you might be able to constrain the automatic user camera by implementing a scene renderer delegate willRenderScene method. You'd have to get the current pointOfView node, check its position and camera parameters, and change them if they're outside whatever bounds you want. But A) I'm not sure this would work, and B) it's probably not a great idea — it's sort of like messing with the internal view hierarchy of a system control class.

Taking Control of ARCamera on Unity3D with Vuforia

The position and rotation of Vuforia's ARcam are determined by their algorithms to give the AR effect. I'd like to know how to do the following:
When some object is clicked the camera goes to some specific position (for that I need to somehow take control of the camera).
Also have to possibility to yield control of the camera back to Vuforia.
You'll want to use a second camera in this instance. Position the second camera at the AR Camera position, then adjust the depths to make the new camera the view that you see. Then you can tween its position to the predefined one you have.
Do the reverse to get control back to the AR Camera.