Hello!
I want to implement colliding 3rd person camera for character. I tried to do it basing on HoverDragController class and AwayPhysics. HoverDragController has three main properties: target (i.e. my character’s body), orbit radius and camera position itself.
The scene has a cube (character) and some boxes of AWPRigidBody type.
To perform camera’s collision I cast a sphere from my character’s position to the desired camera position. If a sphere hits some body I move camera to its position.
c = new Mesh(new SphereGeometry(25), mtl);
c.castsShadows = true;
_camObject.addChild(c);
_camBody = new AWPRigidBody(new AWPSphereShape(25), _camObject, 0.001);
_camBody.gravity = new Vector3D();
_camBody.position = new Vector3D(100, 300, 100);
_physics.addRigidBody(_camBody);
_camBody.addEventListener(AWPCollisionEvent.COLLISION_ADDED, onCameraCollide);
...
private function onCameraCollide(e:AWPCollisionEvent):void {
_camController.radius = _r * .9;
trace('collide at ' + _r);
}
...
/* on enter frame */
// throw a ray from target to camera
var direction:Vector3D = (_camController.pos).subtract(_camController.target);
direction.normalize();
direction.scaleBy(_r);
_camBody.position = (_camController.target).add(direction);
_camBody.gravity = new Vector3D();
_r += 10;
if (_r >= _camController.radiusBounds[1]) {
_r = _camController.radiusBounds[0];
}
It works but a little bit not like I wanted. Assume that large cube is between character and camera. I threw a sphere from camera’s target (i.e. character’s actual position). Sphere collides one of cube’s walls and calls “onCameraCollide”. Camera moves to sphere’s position. Everything is fine. But if a sphere is inside a cube it still calls “onCameraCollide”!!! And my camera occurs inside the walls. Please help me to fix it!