Away3D Object Hover Camera Functionality


/ Published in: ActionScript 3
Save to your folder(s)

Hover around an Object in away3D (will work with papervision3d and other 3D libraries, just plug in the correct data)


Copy this code and paste it in your HTML
  1. //in enterframe function
  2. hoverCamera(currentObject);
  3.  
  4. //function
  5. private function hoverCamera(_currentObject:ObjectContainer3D):void
  6. {
  7. var mX:Number = this.mouseX > 0 ? this.mouseX : 0;
  8. var mZ:Number = this.mouseY > 0 ? this.mouseY : 0;
  9.  
  10. var tarX:Number = 3*(mX - stage.stageWidth/2);
  11. var tarZ:Number = -2*(mZ - stage.stageHeight/2);
  12.  
  13. var dX:Number = camera.x - tarX;
  14. var dZ:Number = camera.z - tarZ;
  15.  
  16. camera.x -= dX*0.25;
  17. camera.z -= dZ*0.25;
  18. camera.lookAt(new Number3D(_currentObject.x, 50, _currentObject.z));
  19. }

URL: http://www.destroyyourcomputer.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.