Will
Will

Reputation: 1619

Player movement/physics with Physi.js

I'm creating a simple game using Three.js as the renderer and Physijs for the physics engine, although this question can easily be generalized to games as a whole.

In games, the player often has physics/movement that seems separate from the physics engine it inhabits. They move with instant acceleration and stop just as instantaneously. Players can fall from a height and collide with other objects (or players) according to the rules of the physics engine, however.

Note that for the purposes of my problem, the player has a camera object which isn't bound by physics, although it can be easily attached to a physical object.

What's the best way to achieve this effect? I've thought of a few solutions, but none seem entirely sufficient:

  1. No physical attachment, translate the player's camera. This, however, would ignore collisions, bypassing the physics engine.

  2. Physical attachment, and apply force to the physical object. This, however, involves frictional forces and places the player's movement at the mercy of the physics engine.

Thoughts? (there was a similar question "https://stackoverflow.com/questions/15822168/how-to-make-a-walk-though-like-fps-tps-games-with-three-js-and-physics-engine", although it received no answers)

Upvotes: 1

Views: 1172

Answers (1)

ABN
ABN

Reputation: 101

If I understood your question correctly you want the camera to have collisiondetection but not be dependent on the physics engine. An alternative way of getting collision detection would be through raytracing, an example of which you can find here: http://stemkoski.github.io/Three.js/Collision-Detection.html

Upvotes: 0

Related Questions