Forums > Jitter

Treating jit.gl.camera like first person view

October 4, 2012 | 4:18 pm

Hi there, I am trying to create a patch that allows the jit.gl.camera to act as first person view for the user.
The first thing I want to achieve is attaching a jit.phys.body to the camera so that it will interact with objects within the world box and also to constrict camera movement within the world box.

Secondly I want to be able to stick the camera to the ground to stop the user from being able to fly around the world box.

I’ve tried a few things but can’t seem to achieve what seems like it should be fairly easy with the new physics engine.

Here is what I have so far.

– Pasted Max Patch, click to expand. –

October 4, 2012 | 7:07 pm

to link a gl.camera and a phys.body to the same anim.drive, you will want to create a parent anim.node, and two child anim.nodes. the anim.drive controls the parent anim.node, and the two child nodes are bound to the gl.camera and the phys.body.

the body should have @kinematic 1 enabled, allowing you to set it’s transforms with the attached anim.node.

this will allow the camera to collide with other objects in the scene, causing them to bounce off the camera, but it won’t prevent the camera from going through those objects if they are static. you will have to handle this yourself, by checking for collisions with those objects.

the patch below demonstrates this.

you could also try a completely different approach, by linking a gl.camera to a dynamic phys.body (not a kinematic one) and move it with forces and impulses. you probably want to add a phys.6dof constraint to the rigidbody to keep it upright.

– Pasted Max Patch, click to expand. –

October 4, 2012 | 9:36 pm

Thanks! really helpful patch and nice idea with the dynamic phys.body, I’ll try and implement it as practise.
With the kinematic phys.body is there any way to easily enable gravitational pull to keep the camera on the ground. and is there a way to prevent the camera from going through the walls of the phys.world? Or is this something that requires clever routing of the position and collision dictionaries?

Thanks again.


October 5, 2012 | 7:37 am

well, no not so much.
you either handle this yourself by analyzing the collisions dictionary, and animating with something like anim.drive, or you give in to the physics forces.

attaching a camera to a dynamic rigid-body via a 6dof spring constraint may prove effective as well.


Viewing 4 posts - 1 through 4 (of 4 total)