My recently work – A Little Ninja Game

Little ninja is a unique innovative virtual character, using next generation physics based animation system to simulate character’s actions. You can play with the little ninja, fight with his little buddy, He will react by real and funny actions.

=======================================
This is not only a game, but also a bipedal action simulator, I’ve developed this technology for a long time, I hope use this to create the more realistic computer virtual character and future create the real bipedal robot. If you like my work, subscribe to my youtube channel, I will keep update the progress.

Two demo:

Physics Based Fighting Game

My recently work is a 2d physics based fighting game that use unity3d as game engine. the main idea is use hinge joint connect each body, and compute target angle in every frame. add some AI control the character keep its balance. more details refer to this paper:

http://www.xbdev.net/misc_demos/demos/fight_characters/paper.pdf

here is a rough demo

update a new demo

JiglibFlash & Away3D4.0 & Molehill

What an exciting day!Molehill has been published. All of us wait for this day for a long time. At the same time the new jiglibfalsh also released, thanks  Away3d team, we can work earlier with this great engine.

what’s new in this version

1, Performance optimization

2, Grid collision system, it’s run faster when there are a lot of rigid bodies.

3, Triangle mesh collision, this support any 3D model(in theory) as a static collision body.

4, Improved stacking bodies

See the demo

note: run this demo you need install the new Flash player Incubator.


you can find the source code from google code

Car Drive On Terrain

大型地图演示
See Demo
Heightmap:

Car Model File
Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
package
{
import flash.display.*;
import flash.events.*;
import flash.ui.Keyboard;
import flash.geom.Vector3D;

import org.papervision3d.cameras.SpringCamera3D;
import org.papervision3d.core.clipping.FrustumClipping;
import org.papervision3d.core.math.Number3D;
import org.papervision3d.materials.*;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
import org.papervision3d.objects.parsers.*;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.lights.PointLight3D;
import org.papervision3d.events.FileLoadEvent;
import org.papervision3d.objects.parsers.Collada;
import org.papervision3d.view.BasicView;
import org.papervision3d.view.stats.StatsView;
import org.papervision3d.view.layer.ViewportLayer;
import org.papervision3d.view.layer.util.ViewportLayerSortMode;

import jiglib.cof.JConfig;
import jiglib.math.*;
import jiglib.physics.*;
import jiglib.geometry.*;
import jiglib.vehicles.JCar;
import jiglib.vehicles.JWheel;
import jiglib.plugin.papervision3d.*;

[SWF(width="800", height="600", backgroundColor="#ffffff", frameRate="60")]
public class CarDriveOnTerrain extends BasicView
{

[Embed(source="res/hightmap2.jpg")]
public var TERRIAN_MAP:Class;

private var springCamera:SpringCamera3D;
private var mylight:PointLight3D;

private var terrain:JTerrain;
private var carBody:JCar;
private var carSkin:Collada;
private var steerFR :DisplayObject3D;
private var steerFL :DisplayObject3D;
private var wheelFR :DisplayObject3D;
private var wheelFL :DisplayObject3D;
private var wheelBR :DisplayObject3D;
private var wheelBL :DisplayObject3D;
private var vplObjects:ViewportLayer;

private var physics:Papervision3DPhysics;

public function CarDriveOnTerrain()
{
super(800, 600, true, true);
stage.addEventListener( KeyboardEvent.KEY_DOWN, keyDownHandler );
stage.addEventListener( KeyboardEvent.KEY_UP, keyUpHandler );

init3D();
}

private function init3D():void
{
physics = new Papervision3DPhysics(scene, 8);

renderer.clipping = new FrustumClipping(FrustumClipping.BOTTOM | FrustumClipping.NEAR);
viewport.containerSprite.sortMode = ViewportLayerSortMode.INDEX_SORT;

springCamera = new SpringCamera3D();
springCamera.y = 5000;
springCamera.mass = 10;
springCamera.damping = 10;
springCamera.stiffness = 1;
springCamera.positionOffset = new Number3D(0, 100, -150);

mylight = new PointLight3D(true, true);
mylight.y = 5000;

var terrainBMD:Bitmap = new TERRIAN_MAP;
var shadeMateria:FlatShadeMaterial = new FlatShadeMaterial(mylight, 0x77ee77);

//create terrain
terrain = physics.createTerrain(terrainBMD.bitmapData, shadeMateria, 10000, 10000, 800, 30, 30);
viewport.getChildLayer(DisplayObject3D(terrain.terrainMesh)).layerIndex = 0;

//init car skin
shadeMateria = new FlatShadeMaterial(mylight,0xeeeeff);
var materiaList:MaterialsList = new MaterialsList();
materiaList.addMaterial(shadeMateria,"all");
carSkin = new Collada("res/car.DAE", materiaList, 0.01);
carSkin.addEventListener(FileLoadEvent.LOAD_COMPLETE,onCarLoaded);

springCamera.target = carSkin;

var stats:StatsView = new StatsView(renderer);
addChild(stats);
}

private function onCarLoaded(e:FileLoadEvent):void
{
scene.addChild(carSkin);

//init car physics
carBody = new JCar(new Pv3dMesh(carSkin));
carBody.setCar(40,5,600);
carBody.chassis.moveTo(new Vector3D( 4000, 100, -3000));
carBody.chassis.mass = 9;
carBody.chassis.sideLengths = new Vector3D(40, 20, 90);
physics.addBody(carBody.chassis);

carBody.setupWheel("WheelFL", new Vector3D( -20, -10, 25), 1.2, 1.2, 3, 10, 0.4, 0.6, 2);
carBody.setupWheel("WheelFR", new Vector3D(20, -10, 25), 1.2, 1.2, 3, 10, 0.4, 0.6, 2);
carBody.setupWheel("WheelBL", new Vector3D( -20, -10, -25), 1.2, 1.2, 3, 10, 0.4, 0.6, 2);
carBody.setupWheel("WheelBR", new Vector3D(20, -10, -25), 1.2, 1.2, 3, 10, 0.4, 0.6, 2);

var shadeMateria:FlatShadeMaterial = new FlatShadeMaterial(mylight, 0x777777);
steerFL = carSkin.getChildByName( "WheelFL", true );
steerFR = carSkin.getChildByName( "WheelFR", true );
wheelFL = carSkin.getChildByName( "WheelFL_PIVOT", true );
wheelFL.material = shadeMateria;
wheelFR = carSkin.getChildByName( "WheelFR_PIVOT", true );
wheelFR.material = shadeMateria;
wheelBL = carSkin.getChildByName( "WheelBL", true );
wheelBL.material = shadeMateria;
wheelBR = carSkin.getChildByName( "WheelBR", true );
wheelBR.material = shadeMateria;

var vplCar:ViewportLayer = viewport.getChildLayer(carSkin.getChildByName("Chassis",true));
vplCar.addDisplayObject3D(wheelFR);
vplCar.addDisplayObject3D(wheelFL);
vplCar.addDisplayObject3D(wheelBR);
vplCar.addDisplayObject3D(wheelBL);
vplCar.layerIndex = 2;

startRendering();
}

private function keyDownHandler(event :KeyboardEvent):void
{
switch(event.keyCode)
{
case Keyboard.UP:
carBody.setAccelerate(1);
break;
case Keyboard.DOWN:
carBody.setAccelerate(-1);
break;
case Keyboard.LEFT:
carBody.setSteer(["WheelFL", "WheelFR"], -1);
break;
case Keyboard.RIGHT:
carBody.setSteer(["WheelFL", "WheelFR"], 1);
break;
case Keyboard.SPACE:
carBody.setHBrake(1);
break;
}
}

private function keyUpHandler(event:KeyboardEvent):void
{
switch(event.keyCode)
{
case Keyboard.UP:
carBody.setAccelerate(0);
break;

case Keyboard.DOWN:
carBody.setAccelerate(0);
break;

case Keyboard.LEFT:
carBody.setSteer(["WheelFL", "WheelFR"], 0);
break;

case Keyboard.RIGHT:
carBody.setSteer(["WheelFL", "WheelFR"], 0);
break;
case Keyboard.SPACE:
carBody.setHBrake(0);
}
}

private function updateWheelSkin():void
{
steerFL.rotationY = carBody.wheels["WheelFL"].getSteerAngle();
steerFR.rotationY = carBody.wheels["WheelFR"].getSteerAngle();

wheelFL.pitch(carBody.wheels["WheelFL"].getRollAngle());
wheelFR.pitch(carBody.wheels["WheelFR"].getRollAngle());
wheelBL.roll(carBody.wheels["WheelBL"].getRollAngle());
wheelBR.roll(carBody.wheels["WheelBR"].getRollAngle());

steerFL.y = carBody.wheels["WheelFL"].getActualPos().y;
steerFR.y = carBody.wheels["WheelFR"].getActualPos().y;
wheelBL.y = carBody.wheels["WheelBL"].getActualPos().y;
wheelBR.y = carBody.wheels["WheelBR"].getActualPos().y;
}

protected override function onRenderTick(event:Event = null):void {
//physics.step();
physics.engine.integrate(0.12);
updateWheelSkin();

renderer.renderScene(scene, springCamera, viewport);
}
}
}

Terrain

基于高度图的地形支持
See Demo
Heightmap:

Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
package {
import flash.display.Bitmap;
import flash.ui.Keyboard;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.geom.Vector3D;

import org.papervision3d.cameras.CameraType;
import org.papervision3d.lights.PointLight3D;
import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.primitives.*;
import org.papervision3d.view.BasicView;
import org.papervision3d.view.stats.StatsView;
import org.papervision3d.view.layer.ViewportLayer;
import org.papervision3d.view.layer.util.ViewportLayerSortMode;

import jiglib.cof.JConfig;
import jiglib.geometry.*;
import jiglib.math.*;
import jiglib.physics.RigidBody;
import jiglib.plugin.papervision3d.*;

[SWF(width="800", height="600", backgroundColor="#ffffff", frameRate="60")]
public class TestTerrain extends BasicView
{
[Embed(source="res/hightmap1.jpg")]
public var TERRIAN_MAP:Class;

private var terrain:JTerrain;
private var ballBody:Vector.;
private var boxBody:Vector.;
private var capsuleBody:Vector.;
private var physics:Papervision3DPhysics;

private var keyRight :Boolean = false;
private var keyLeft :Boolean = false;
private var keyForward :Boolean = false;
private var keyReverse :Boolean = false;
private var keyUp:Boolean = false;

public function TestTerrain()
{
super(800, 600, true, true, CameraType.TARGET);

stage.addEventListener( KeyboardEvent.KEY_DOWN, keyDownHandler);
stage.addEventListener( KeyboardEvent.KEY_UP, keyUpHandler);

init();
var stats:StatsView = new StatsView(renderer);
addChild(stats);
}

private function init():void
{
viewport.containerSprite.sortMode = ViewportLayerSortMode.INDEX_SORT;

physics = new Papervision3DPhysics(scene, 8);

var mylight:PointLight3D = new PointLight3D(true, true);
mylight.y = 600;
mylight.z = -400;
camera.y = mylight.y;
camera.z = mylight.z;

var terrainBMD:Bitmap = new TERRIAN_MAP;
var shadeMateria:FlatShadeMaterial = new FlatShadeMaterial(mylight, 0x77ee77);

//create terrain
terrain = physics.createTerrain(terrainBMD.bitmapData, shadeMateria, 800, 800, 350, 10, 10);
terrain.friction = 0.2;
viewport.getChildLayer(DisplayObject3D(terrain.terrainMesh)).layerIndex = 1;

var vplObjects:ViewportLayer = new ViewportLayer(viewport,null);
vplObjects.layerIndex = 2;
vplObjects.sortMode = ViewportLayerSortMode.Z_SORT;
viewport.containerSprite.addLayer(vplObjects);

ballBody = new Vector.();
var color:uint;
for (var i:int = 0; i < 6; i++)
{
color = (i == 0)?0xff8888:0xeeee00;
shadeMateria = new FlatShadeMaterial(mylight, color);
ballBody[i] = physics.createSphere(shadeMateria, 25);
ballBody[i].moveTo(new Vector3D( 0, 100 + (60 * i + 60), 200));
vplObjects.addDisplayObject3D(physics.getMesh(ballBody[i]));
}
ballBody[0].mass = 10;

shadeMateria = new FlatShadeMaterial(mylight,0xeeee00);
var materiaList:MaterialsList = new MaterialsList();
materiaList.addMaterial(shadeMateria,"all");
boxBody=new Vector.();
for (i = 0; i < 2; i++)
{
boxBody[i] = physics.createCube(materiaList, 50, 40, 30);
boxBody[i].moveTo(new Vector3D(-200, 100 + (50 * i + 50), 0));
vplObjects.addDisplayObject3D(physics.getMesh(boxBody[i]));
}

var capsuleSkin:Cylinder;
capsuleBody = new Vector.();
for (i = 0; i < 2; i++)
{
capsuleSkin = new Cylinder(shadeMateria, 20, 50);
scene.addChild(capsuleSkin);
vplObjects.addDisplayObject3D(capsuleSkin);

capsuleBody[i] = new JCapsule(new Pv3dMesh(capsuleSkin), 20, 30);
capsuleBody[i].moveTo(new Vector3D(200, 100 + (80 * i + 80), 0));
physics.addBody(capsuleBody[i]);
}

startRendering();
}

private function keyDownHandler(event:KeyboardEvent):void
{
switch(event.keyCode)
{
case Keyboard.UP:
keyForward = true;
keyReverse = false;
break;

case Keyboard.DOWN:
keyReverse = true;
keyForward = false;
break;

case Keyboard.LEFT:
keyLeft = true;
keyRight = false;
break;

case Keyboard.RIGHT:
keyRight = true;
keyLeft = false;
break;
case Keyboard.SPACE:
keyUp = true;
break;
}
}

private function keyUpHandler(event:KeyboardEvent):void
{
switch(event.keyCode)
{
case Keyboard.UP:
keyForward = false;
break;

case Keyboard.DOWN:
keyReverse = false;
break;

case Keyboard.LEFT:
keyLeft = false;
break;

case Keyboard.RIGHT:
keyRight = false;
break;
case Keyboard.SPACE:
keyUp=false;
}
}

override protected function onRenderTick(event:Event=null):void
{
if(keyLeft)
{
ballBody[0].addWorldForce(new Vector3D(-100,0,0),ballBody[0].currentState.position);
}
if(keyRight)
{
ballBody[0].addWorldForce(new Vector3D(100,0,0),ballBody[0].currentState.position);
}
if(keyForward)
{
ballBody[0].addWorldForce(new Vector3D(0,0,100),ballBody[0].currentState.position);
}
if(keyReverse)
{
ballBody[0].addWorldForce(new Vector3D(0,0,-100),ballBody[0].currentState.position);
}
if(keyUp)
{
ballBody[0].addWorldForce(new Vector3D(0, 100, 0), ballBody[0].currentState.position);
}

physics.engine.integrate(0.2);
renderer.renderScene(scene, camera, viewport);
}
}
}

CarDrive

交通工具模拟
See Demo
Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
package  
{
    import flash.display.*;
    import flash.events.*;
    import flash.ui.Keyboard;
    import flash.geom.Vector3D;
   
    import org.papervision3d.cameras.CameraType;
    import org.papervision3d.materials.*;
    import org.papervision3d.materials.utils.MaterialsList;
    import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
    import org.papervision3d.objects.parsers.*;
    import org.papervision3d.objects.DisplayObject3D;
    import org.papervision3d.lights.PointLight3D;
    import org.papervision3d.events.FileLoadEvent;
    import org.papervision3d.objects.parsers.Collada;
    import org.papervision3d.view.BasicView;
    import org.papervision3d.view.stats.StatsView;
    import org.papervision3d.view.layer.ViewportLayer;
    import org.papervision3d.view.layer.util.ViewportLayerSortMode;

    import jiglib.math.*;
    import jiglib.physics.*;
    import jiglib.vehicles.JCar;
    import jiglib.vehicles.JWheel;
    import jiglib.plugin.papervision3d.*;

    [SWF(width="800", height="600", backgroundColor="#ffffff", frameRate="60")]
    public class CarDrive extends BasicView
    {
        private var mylight:PointLight3D;
       
        private var carBody:JCar;
        private var carSkin:Collada;
        private var steerFR :DisplayObject3D;
        private var steerFL :DisplayObject3D;
        private var wheelFR :DisplayObject3D;
        private var wheelFL :DisplayObject3D;
        private var wheelBR :DisplayObject3D;
        private var wheelBL :DisplayObject3D;
        private var vplObjects:ViewportLayer;
       
        private var physics:Papervision3DPhysics;
       
        public function CarDrive()
        {
            super(800, 600, true, true, CameraType.TARGET);
            stage.addEventListener( KeyboardEvent.KEY_DOWN, keyDownHandler );
            stage.addEventListener( KeyboardEvent.KEY_UP, keyUpHandler );
           
            init3D();
        }
       
        private function init3D():void
        {
            physics = new Papervision3DPhysics(scene, 6);
            viewport.containerSprite.sortMode = ViewportLayerSortMode.INDEX_SORT;
             
            mylight = new PointLight3D(true, true);
            mylight.y = 300;
            mylight.z = -400;
             
            var shadeMateria:FlatShadeMaterial = new FlatShadeMaterial(mylight, 0x77ee77);
            var ground:RigidBody = physics.createGround(shadeMateria, 500, 0);
            viewport.getChildLayer(physics.getMesh(ground)).layerIndex = 0;
           
           
            //init car skin
            shadeMateria = new FlatShadeMaterial(mylight,0xeeeeff);
            var materiaList:MaterialsList = new MaterialsList();
            materiaList.addMaterial(shadeMateria,"all");
            carSkin = new Collada("res/car.DAE", materiaList, 0.01);
            carSkin.addEventListener(FileLoadEvent.LOAD_COMPLETE,onCarLoaded);
             
            camera.y = mylight.y;
            camera.z = mylight.z;
             
            var stats:StatsView = new StatsView(renderer);
            addChild(stats);
        }
       
        private function onCarLoaded(e:FileLoadEvent):void
        {
            scene.addChild(carSkin);
             
            //init car physics
            carBody = new JCar(new Pv3dMesh(carSkin));
            carBody.setCar(40,5,500);
            carBody.chassis.moveTo(new Vector3D( 0, 100, 0));
            carBody.chassis.rotationY = -90;
            carBody.chassis.mass = 9;
            carBody.chassis.sideLengths = new Vector3D(40, 20, 90);
            physics.addBody(carBody.chassis);
             
            carBody.setupWheel("WheelFL", new Vector3D( -20, -10, 25), 1.2, 1.2, 3, 8, 0.4, 0.6, 2);
            carBody.setupWheel("WheelFR", new Vector3D(20, -10, 25), 1.2, 1.2, 3, 8, 0.4, 0.6, 2);
            carBody.setupWheel("WheelBL", new Vector3D( -20, -10, -25), 1.2, 1.2, 3, 8, 0.4, 0.6, 2);
            carBody.setupWheel("WheelBR", new Vector3D(20, -10, -25), 1.2, 1.2, 3, 8, 0.4, 0.6, 2);
             
            var shadeMateria:FlatShadeMaterial = new FlatShadeMaterial(mylight, 0x777777);
            steerFL = carSkin.getChildByName( "WheelFL", true );
            steerFR = carSkin.getChildByName( "WheelFR", true );
            wheelFL = carSkin.getChildByName( "WheelFL_PIVOT", true );
            wheelFL.material = shadeMateria;
            wheelFR = carSkin.getChildByName( "WheelFR_PIVOT", true );
            wheelFR.material = shadeMateria;
            wheelBL = carSkin.getChildByName( "WheelBL", true );
            wheelBL.material = shadeMateria;
            wheelBR = carSkin.getChildByName( "WheelBR", true );
            wheelBR.material = shadeMateria;
             
            var vplCar:ViewportLayer = viewport.getChildLayer(carSkin.getChildByName("Chassis",true));
            vplCar.addDisplayObject3D(wheelFR);
            vplCar.addDisplayObject3D(wheelFL);
            vplCar.addDisplayObject3D(wheelBR);
            vplCar.addDisplayObject3D(wheelBL);
            vplCar.layerIndex = 2;
           
            shadeMateria = new FlatShadeMaterial(mylight, 0x77ee77);
            var materiaList :MaterialsList = new MaterialsList();
            materiaList.addMaterial(shadeMateria, "all");
            var ramp1:RigidBody = physics.createCube(materiaList, 400, 200, 10);
            ramp1.movable = false;
            ramp1.moveTo(new Vector3D(0, 33, 250));
            ramp1.rotationX = -20;
            vplCar.addDisplayObject3D(physics.getMesh(ramp1));
           
            var ramp2:RigidBody = physics.createCube(materiaList, 400, 200, 10);
            ramp2.movable = false;
            ramp2.moveTo(new Vector3D(0, 33, 440));
            ramp2.rotationX = 20;
            vplCar.addDisplayObject3D(physics.getMesh(ramp2));
           
            shadeMateria = new FlatShadeMaterial(mylight, 0xeeee00);
            materiaList = new MaterialsList();
            materiaList.addMaterial(shadeMateria, "all");
            var boxBody:Array = new Array();
            for (var i:int = 0; i < 2; i++)
            {
                boxBody[i] = physics.createCube(materiaList, 40, 40, 40);
                boxBody[i].moveTo(new Vector3D(-100, 30 + (50 * i + 50), 0));
                vplCar.addDisplayObject3D(boxBody[i].skin.mesh);
            }
           
            startRendering();
        }
       
        private function keyDownHandler(event :KeyboardEvent):void
        {
            switch(event.keyCode)
            {
                case Keyboard.UP:
                    carBody.setAccelerate(1);
                    break;
                case Keyboard.DOWN:
                    carBody.setAccelerate(-1);
                    break;
                case Keyboard.LEFT:
                    carBody.setSteer(["WheelFL", "WheelFR"], -1);
                    break;
                case Keyboard.RIGHT:
                    carBody.setSteer(["WheelFL", "WheelFR"], 1);
                    break;
                case Keyboard.SPACE:
                    carBody.setHBrake(1);
                    break;
            }
        }


        private function keyUpHandler(event:KeyboardEvent):void
        {
            switch(event.keyCode)
            {
                case Keyboard.UP:
                    carBody.setAccelerate(0);
                    break;
                   
                case Keyboard.DOWN:
                    carBody.setAccelerate(0);
                    break;
                   
                case Keyboard.LEFT:
                    carBody.setSteer(["WheelFL", "WheelFR"], 0);
                    break;
                   
                case Keyboard.RIGHT:
                    carBody.setSteer(["WheelFL", "WheelFR"], 0);
                    break;
                case Keyboard.SPACE:
                   carBody.setHBrake(0);
            }
        }
         
        private function updateWheelSkin():void
        {
            steerFL.rotationY = carBody.wheels["WheelFL"].getSteerAngle();
            steerFR.rotationY = carBody.wheels["WheelFR"].getSteerAngle();
           
            wheelFL.pitch(carBody.wheels["WheelFL"].getRollAngle());
            wheelFR.pitch(carBody.wheels["WheelFR"].getRollAngle());
            wheelBL.roll(carBody.wheels["WheelBL"].getRollAngle());
            wheelBR.roll(carBody.wheels["WheelBR"].getRollAngle());
           
            steerFL.y = carBody.wheels["WheelFL"].getActualPos().y;
            steerFR.y = carBody.wheels["WheelFR"].getActualPos().y;
            wheelBL.y = carBody.wheels["WheelBL"].getActualPos().y;
            wheelBR.y = carBody.wheels["WheelBR"].getActualPos().y;
        }
         
        protected override function onRenderTick(event:Event = null):void {
            //physics.step();
            physics.engine.integrate(0.12);
            updateWheelSkin();
            super.onRenderTick(event);
        }
    }
}