Is A camera possible in this (see code) Or any type of following....
Im looking into making a game thats 3D or atleast creates the illusion as i dont want to use 3D models, too much cpu usage.
Anyways i have heard of loads of ways to implement it read ebook wathed tutorials ect. But they are not usefull to me. I need to be shown and then read the code a few times implementing it on many other examples.
Anyways the real question is in the title, I need some sort of Camera, or at least some way of following my car whist its on the track.
Im ok at making 2D games but 3D baffled me more than you can imageine.
I have read that you can make the 3D effect by titlting the ground by 90 degrees and facing the car upright, then if the car moves left then the ground moves right ect. But i have no idea of how to implemnt this im open to ideas and will CREDIT whoever helps me in the game credits.
Any ways my current code:
racing.as - Document class.
package {
import flash.display.Sprite;
public class racing extends Sprite {
public var car:car_mc;
public var ground:ground_mc = new ground_mc();
public function racing():void {
car = new car_mc(450,300);
addChild(ground);
addChild(car);
}
}
}
car_mc.as
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.geom.Point;
public class car_mc extends Sprite {
public var acceleration:Number=0.4;
public var speed_decay:Number=0.96;
public var rotation_step:Number=10;
public var max_speed:Number=10;
public var back_speed:Number=1;
public var speed:Number=0;
public var accelerate,brake,turn_left,turn_right:Boolean=false;
public function car_mc(posx:int,posy:int):void {
x=posx;
y=posy;
addEventListener(Event.ADDED_TO_STAGE,init);
}
public function init(e:Event):void {
addEventListener(Event.ENTER_FRAME,on_enter_frame);
stage.addEventListener(KeyboardEvent.KEY_DOWN,on_key_down);
stage.addEventListener(KeyboardEvent.KEY_UP,on_key_up);
}
public function on_enter_frame(e:Event):void {
if (accelerate&&speed<max_speed) {
speed+=acceleration;
}
if (brake&&speed>-1) {
speed-=back_speed;
}
var speed_x:Number=Math.sin(rotation*0.0174532925)*speed;
var speed_y:Number=- Math.cos(rotation*0.0174532925)*speed;
if (turn_left) {
rotation -= rotation_step*(speed/max_speed);
}
if (turn_right) {
rotation += rotation_step*(speed/max_speed);
}
y+=speed_y;
x+=speed_x;
var point_left:Point=new Point(-9,0);
var point_right:Point=new Point(9,0);
var point_front:Point=new Point(0,-13);
var point_back:Point=new Point(0,13);
point_left=localToGlobal(point_left);
point_right=localToGlobal(point_right);
point_front=localToGlobal(point_front);
point_back=localToGlobal(point_back);
var par:racing=this.parent as racing;
if (par.ground.hitTestPoint(point_left.x,point_left.y,true)) {
rotation+=5;
speed*=0.85;
}
if (par.ground.hitTestPoint(point_right.x,point_right.y,true)) {
rotation-=5;
speed*=0.85;
}
if (par.ground.hitTestPoint(point_front.x,point_front.y,true)) {
speed*=0.55;
}
if (par.ground.hitTestPoint(point_back.x,point_back.y,true)) {
speed*=0.55;
}
if (Math.abs(speed)>0.3) {
speed*=speed_decay;
} else {
speed=0;
}
}
public function on_key_down(e:KeyboardEvent):void {
if (e.keyCode==38) {
accelerate=true;
}
if (e.keyCode==40) {
brake=true;
}
if (e.keyCode==37) {
turn_left=true;
}
if (e.keyCode==39) {
turn_right=true;
}
}
public function on_key_up(e:KeyboardEvent):void {
if (e.keyCode==38) {
accelerate=false;
}
if (e.keyCode==40) {
brake=false;
}
if (e.keyCode==37) {
turn_left=false;
}
if (e.keyCode==39) {
turn_right=false;
}
}
}
}