Hi,
I just finished my multiplayer gateway so i want to build a multiplayer game. I ‘m usin Away3d 4 but have some problems:
My first problem is about trigonometry.
I want to fallow an object with camera form a distance and height (for example 100px from behind and 50px from top). That object can rotate in 3
axis. For a quick solution i made a 3D container and put both camera and object in it and rotatin and movin container instead of weichle
like that:
private function init():void{
...
_container = new ObjectContainer3D();
_container.addChild(_camera);
_camera.y = 100;
view.scene.addChild(_container);
...
}
private function onResourceComplete(e:LoaderEvent):void {
...
_container.addChild(_loader);
...
}
private function onEnterFrame(event:Event):void {
...
_container.rotationY += ((mouseX - (stage.width /2) )* 0.004);
_container.rotationX += ((mouseY - (stage.height /2) )* 0.004);
_container.rotationZ += ((mouseX - (stage.width /2) )* 0.001);
_container.moveForward(currentSpeed);
// _camera.x = ;
// _camera.y = ;
// _camera.z = ;
_camera.lookAt(_loader.position);
...
}
but this is not enaught. I want to add easing animations to camera on bounce, crash or any another event. I need to samehow calculate camera’s
position from object’s position and angles. i found some simples.
var targetX:Number = car.x + Math.sin(car.rotationZ)*cameraDistance;
var targetY:Number = car.y - Math.cos(car.rotationZ)*cameraDistance;
var targetZRotation:Number = car.rotationZ+Math.PI;
camera.x -= (camera.x - targetX)*.2;
camera.y -= (camera.y - targetY)*.2;
camera.rotationZ -= (camera.rotationZ - targetZRotation)*.2;
in this simple car only rotates on z axis but my weichle will rotate x,y and z axis together. Then i found a formula for 3D rotation
x1 = cos(angleZ) * x - sin(angleZ) * y;
y1 = cos(angleZ) * y + sin(angleZ) * x;
x1 = cos(angleY) * x - sin(angleY) * z;
z1 = cos(angleY) * z + sin(angleY) * x;
y1 = cos(angleX) * y - sin(angleX) * z;
z1 = cos(angleX) * z + sin(angleX) * y;
but my trigonometry not good enaught to correct it to add distance and height ( i did’t even understand what it says).
as a 2nd problem ofcourse my players need to have their name on their weichles and looks like on version 4 Away3D don’t have a common 3DText support. i found a simple on forum
var newText:TextField = new TextField();
newText.width = 300;
newText.text = "My dynamic text";
var txtForm:TextFormat = new TextFormat();
txtForm.color = 0xffffff;
txtForm.size = 48;
newText.setTextFormat(txtForm);
var btTxt:BitmapData = new BitmapData(1024, 1024, true, 0x000000);
btTxt.draw(newText, null, null, null, null, true);
var myTxtMat : BitmapMaterial = new BitmapMaterial(btTxt, true, false, true);
_board = new Sprite3D(myTxtMat, 128, 64);
but don’t know why i can’t see text anywhere. again for a quick solutin i’m going to add TextFields to directly to my Sprite but can’t find a way to
change 3D vertex of an object in scene to point in stage.
Thanx for any help.
Edit: I mistakely pressed update buton instead of preview. put other half of post