# Somebody,,can help me? I wanna make a game as3 using this script.Please

**URL:** <https://forum.kirupa.com/t/somebody-can-help-me-i-wanna-make-a-game-as3-using-this-script-please/329364>\
**Category:** Uncategorized\
**Created:** [August 17, 2012, 5:33pm UTC](https://forum.kirupa.com/t/somebody-can-help-me-i-wanna-make-a-game-as3-using-this-script-please/329364 "2012-08-17T17:33:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ostkill](https://avatars.discourse-cdn.com/v4/letter/o/3ec8ea/32.png) [@Ostkill](https://forum.kirupa.com/u/Ostkill)\
**Post date:** [August 17, 2012, 5:33pm UTC](https://forum.kirupa.com/t/somebody-can-help-me-i-wanna-make-a-game-as3-using-this-script-please/329364/1 "2012-08-17T17:33:29Z")

</div>

**​**

// create a scene movieclip to contain all 3D elements  
// and center it on the screen.  
this.createEmptyMovieClip(“theScene”, 1);  
theScene.\_x = 150;  
theScene.\_y = 150;  
theScene.depth = 1; // variable to control depth placement

// now we’re going to create an array to keep track of all the  
// objects in the scene. That way, to position all the objects  
// you just need to loop through this array.  
objectsInScene = new Array();

// now make a camera object to serve as the users view or camera  
// position within the cockpit of the car  
cameraView = new Object();  
cameraView.x = 0;  
cameraView.y = -100;  
cameraView.z = 0;  
// set a variable for user (camera) velocity  
cameraView.velocity = 0;

// focal length to determine perspective scaling  
focalLength = 300;

// the objects in this scene (other than the cameraView) are going to be  
// a few cars and some marker clips to define the edge of the road. We’ll  
// need to set up functions to handle their actions when the scene is  
// being run. They’ll be declared next

// CARS  
displayCar = function(){  
var x = this.x - cameraView.x;  
var y = this.y - cameraView.y;  
var z = this.z - cameraView.z;  
if (z \< 4000){  
if (z \< 0){  
this.z += 3000;  
this.x = 200-Math.random()\*400;  
x = this.x - cameraView.x;  
}  
this.z += this.velocity;  
z = this.z - cameraView.z;  
}

```
var scaleRatio = focalLength/(focalLength + z);
this._x = x * scaleRatio;
this._y = y * scaleRatio;
this._xscale = this._yscale = 100 * scaleRatio;
this.swapDepths(Math.round(-z));

```

}

// TIRES  
displayTire = function(){  
var x = this.x - cameraView.x;  
var y = this.y - cameraView.y;  
var z = this.z - cameraView.z;  
if (z \< 0){  
this.z += 3000;  
z = this.z - cameraView.z;  
}

```
var scaleRatio = focalLength/(focalLength + z);
this._x = x * scaleRatio;
this._y = y * scaleRatio;
this._xscale = this._yscale = 100 * scaleRatio;
this.swapDepths(Math.round(-z));

```

}

// now its time to populate the scene. The edges of the road will be  
// determined by a line of markers on each side and there will be, in  
// addition to that, 3 other cars on the track. They can be attached  
// and added now - the enterFrame actions will striaghten them out when  
// the movie is running.  
// first we’ll add the 3 cars  
for (i=0; i\<3; i++){  
attachedObj = theScene.attachMovie(“car”, “car”+i, theScene.depth++);  
attachedObj.x = 200 - Math.random()_400;  
attachedObj.y = 0;  
attachedObj.z = 500+Math.random()1000;  
attachedObj.velocity = 20 + i5;  
attachedObj.display = displayCar;  
objectsInScene.push(attachedObj);  
}  
// now we’ll add 20 markers, 10 on each side of the road, to  
// define where the road is  
for (i=0; i\<20; i++){  
attachedObj = theScene.attachMovie(“tire”, “tire”+i, theScene.depth++);  
if (i \< 10){  
attachedObj.x = -250;  
attachedObj.z = i_300;  
}else{  
attachedObj.x = 250;  
attachedObj.z = 150 + (i-10)\*300;  
}  
attachedObj.y = 0;  
attachedObj.display = displayTire;  
objectsInScene.push(attachedObj);  
}

// a function to move back and forth. This will be applied to  
// the onEnterFrame of each figure in the scene  
drive = function(){

```
// alter the z value of the camera based on UP and DOWN arrow
// keys, adding that to the camera's velocity.
// in addition, we can add some resistance from just wind and
// friction and things. So if you let off the arrow keys, you'll
// slowly come to a stop
if (Key.isDown(Key.UP)) cameraView.velocity += 2;
else cameraView.velocity *= .95;
if (Key.isDown(Key.DOWN)) cameraView.velocity -= 2;

// make sure the velocity is within some limits
if (cameraView.velocity &lt; 0) cameraView.velocity = 0;
else if (cameraView.velocity &gt; 80) cameraView.velocity = 80;
// add the velocity to the z 
cameraView.z += cameraView.velocity;

// move the camera left or right based on the
// LEFT and RIGHT arrow keys. This will be based on velocity
// since the faster you're going, the faster you can turn
if (Key.isDown(Key.LEFT)) cameraView.x -= cameraView.velocity/5;
if (Key.isDown(Key.RIGHT)) cameraView.x += cameraView.velocity/5;
// keep within some limits
if (cameraView.x &lt; -200) cameraView.x = -200;
else if (cameraView.x &gt; 200) cameraView.x = 200;

// Now, with the camera moved, you need to perform the offset
// of the camera's position to everything else in the scene
for (var i=0; i&lt;objectsInScene.length; i++){
	objectsInScene*.display();
}

```

};

// make each figure run backAndForth every frame  
theScene.onEnterFrame = drive;
