gyllensand
gyllensand

Reputation: 21

Three.js - Chase camera for moving sphere rolling on a plane using Physi.js without the camera following the sphere's rotation?

So I have a flat plane, and I'm using up, down, right and left to roll a sphere along it using Physi.js. I want to apply a chase camera to the sphere, but I can't prevent the camera to follow the sphere's rotation? I want the camera to stay behind the sphere, following it's z.axis but prevent it to rotate every time the sphere spins.

Anyone's got a clue?

Upvotes: 1

Views: 1119

Answers (2)

user5522551
user5522551

Reputation:

function chaseMesh(camera, mesh){
    camera.position.z = mesh.position.z;
    camera.lookAt(mesh.position);
}

Just call that every time you want to reposition your camera with the parameters.

Upvotes: 1

Joey
Joey

Reputation: 10965

Create a generic THREE.Object3D(), and add both the sphere and the camera to it. Do your translations on the parent object, and only use the sphere itself when doing rotations.

Upvotes: 0

Related Questions