package{
import away3d.cameras.*;
import away3d.containers.Scene3D;
import away3d.containers.View3D;
import away3d.core.math.Number3D;
import away3d.lights.*;
import away3d.loaders.*;
import away3d.materials.*;
import away3d.primitives.*;
import flash.display.Sprite;
import flash.events.*;
import flash.ui.Keyboard;
[SWF(width="1024", height="768", frameRate="30",
backgroundColor="0xFAFAFA")]
public class camera extends Sprite{
private var scene:Scene3D;
private var cam:SpringCam;
private var view:View3D;
private var Cube01:Cube;
private var Cylinder01:Cylinder;
private var Sphere01:WireSphere;
private var Plane01:Plane;
private var lastKey:uint;
private var keyIsDown:Boolean = false;
public function camera(){
scene=new Scene3D;
cam=new SpringCam({target:Cube01});
view=new View3D({scene:scene, x:stage.stageWidth/2,
y:stage.stageHeight/2});
addChild(view);
view.scene.addChild(cam);
Cube01=new Cube({height:10, width:10, depth:10, x:20,
y:10, z:0});
view.scene.addChild(Cube01);
cam.mass = 10;
cam.damping = 10;
cam.stiffness = 4;
cam.target = Cube01;
cam.lookAt(Cube01.position);
cam.lookOffset = new Number3D(0,0,500);
cam.positionOffset = new Number3D(0, 0, 100);
var axis:Trident=new Trident(150);
view.scene.addChild(axis);
Plane01= new Plane({height:100, width:100, x:0, y:0,
z:0});
view.scene.addChild(Plane01);
view.camera=cam;
view.render();
this.stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDown);
this.stage.addEventListener(KeyboardEvent.KEY_UP,keyUp);
this.addEventListener(Event.ENTER_FRAME,onEnterFrame);
}
private function keyDown(e:KeyboardEvent):void
{
lastKey = e.keyCode;
keyIsDown = true;
}
private function keyUp(e:KeyboardEvent):void
{
keyIsDown = false;
}
private function onEnterFrame(e:Event):void
{
if(keyIsDown){
switch(lastKey){
case Keyboard.RIGHT :
Cube01.yaw(2); break;
case Keyboard.LEFT :
Cube01.yaw(-2); break;
case Keyboard.UP :
Cube01.moveForward(10); break;
case Keyboard.DOWN :
Cube01.moveBackward(10); break;
}
}
cam.view;
view.render();
}
}
}
On 14 мар, 14:46, sascha <[email protected]> wrote:
> Hi I'm trying to utilize a SpringCam as a camera for a first person
> game camera style movement.
> I've created a simple cube with represents the player and set it as
> the target for the spring cam. I then move the player mesh into four
> directions according to cursor keys held down but the spring cam wont
> follow. What am I doing wrong?
>
> I've tried following this tute so
> far:http://www.brighthub.com/hubfolio/matthew-casperson/articles/49028.aspx
> but it seems to be very outdated. Is there maybe any more up-to-date
> tutorial available somewhere?
>
> What I'm trying to achieve is a decent FPS style camera where the
> player can move forward/backward with cursor keys UP/DOWN, strafe left
> and right with LEFT/RIGHT cursor keys and also use the camera to
> freely rotate the view around the player mesh. Is this even possible
> with Away3D? I've read that there are limitations because of how the
> mouse works in the Flash Player but I wont so easily write this off.