3rd person camera collision

Software: Away3D 4.x

Avatar
kurono, Sr. Member
Posted: 03 March 2012 09:00 AM   Total Posts: 103

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.

= new Mesh(new SphereGeometry(25), mtl);
   
c.castsShadows true;
   
_camObject.addChild(c);
   
_camBody = new AWPRigidBody(new AWPSphereShape(25), _camObject0.001);
   
_camBody.gravity = new Vector3D();
   
_camBody.position = new Vector3D(100300100);
   
_physics.addRigidBody(_camBody);
   
_camBody.addEventListener(AWPCollisionEvent.COLLISION_ADDEDonCameraCollide);

...

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!

   

Avatar
kurono, Sr. Member
Posted: 03 March 2012 09:27 AM   Total Posts: 103   [ # 1 ]

Probably I should to set constant velocity (10) for this sphere instead of force movement according to direction. In this case, once collide with wall, sphere can’t occur inside it.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X