nicktendo Posted June 12, 2017 Share Posted June 12, 2017 Is it possible to add a physics impostor to a free camera with cannon.js that allows it to collide with rigid bodies just like any other mesh that has a physics impostor? I also need the free camera to maintain the standard keyboard/mouse controls. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted June 13, 2017 Share Posted June 13, 2017 Hi again Nick. No, that's not possible. Sorry. There is a rather large issue involved. WHO is the boss of the camera? Example: Your keypresses and mouse events are telling the camera to do something, WHILE the camera (a physics-active mesh 'camera gizmo' that the camera is parented-to)... is "recoiling" (restitution bounce-off) from a recent collision with another mesh. Is the keypress the boss? Or is the physicsImpostor attached to the camera gizmo... the boss? Generally speaking, physicsImpostors are the boss, once they are attached to a mesh (which a camera might be parented-to). But ponder this, if you please. 1. Make tiny or invisible standard box. 2. Set freeCamera.parent = box. Adjust camera rotation as needed. 3. RE-program all camera and mouse events... to do box.physicsImpostor.setLinearVelocity(new BABYLON.Vector3(?, ?, ?)); You won't need to setAngularVelocity for camera turning/tilting, because the camera should still be able to turn/tilt using its own .rotation property, even after being parented to box. (I think) See what we are after here? We are building a remote-control physics-active "robot" to carry the camera for us. The robot "box" must be in same position as camera, and will likely need to be .visibility = 0; (so the camera can see through it). Experiment with that visibility stuff. Sometimes it is helpful to do box.showBoundingBox = true; ...to help see invisible mesh, while coding. Also handy to have 2 cameras... and quick-switch hot key. One cam on-robot, another cam for wider view - for watching robot maneuvering thrusters. Demented scientist side-note: It is fairly easy to activate a Babylon ParticleSystem on the robot box... that visually blasts particles... in the opposite direction of forceVector. Activate on WASD onKeyDown, shut-off onKeyUp. It will make robot nav testing... lots more fun. heh For example, applyImpulse needs a force vector. It will PUSH the box in that direction. Use thatDirection.negate() as the particle emitter direction. Easy! (not really. lots of thinking needed - hurts a little bit) Does mouse/keypress -driving a physics-active "box" using .setLinearVelocity()... SUCK to code-up, you ask? Yep, it sucks to code. But, I'm thinking that this is the closest you can get to "physics-on-the camera". When you said "I also need the free camera to maintain the standard keyboard/mouse controls."... the challenge got MUCH more difficult. NEARLY impossible. But, the entire forum is here to help, and to think-up better ideas than mine. SO, let's watch/listen for a while, and see if others have good ideas. Meantime, you can "play" with my idea. Set-up some WASD keypressHandlers, and try performing some setLinearVelocities on a physics-active box. You can also use applyImpulse (instead of setLinearVelocity), both do the same thing IF your impulse "contact point" is mesh.getAbsolutePosition(). When using applyImpulse, you must thrust/impulse at the dead-center of the mesh, or else the thrust will induce rotation. If you thrust dead-center, the mesh will ONLY translate (change position), and NOT rotate at all. It will translate the mesh... in the direction and magnitude of the "force vector". Try thrusting-around a low-friction box... upon the icy ground... with keypresses. It's easy to get a box sliding. Getting it to stop... that is another challenge. Use mass+friction to gently stop, or setLinearVelocity to zero, of course. Use a box ONLY, for now. Spheres and sphereImpostors... roll. That will make the camera viewers motion-sick (but there IS a way to "fix"/lock the rotation of a physics-active sphere, and spheres make nice colliders. So, you might change to that, later.) Hope this helps. nicktendo and GameMonetize 2 Quote Link to comment Share on other sites More sharing options...
nicktendo Posted June 13, 2017 Author Share Posted June 13, 2017 @Wingnut Thank you so much, great explanation! Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.