I Need Help On Action Scripting

I AM DOING A SCHOOL PROJECT AND I CANT FIQURE OUT HOW TO MAKE MY SHIP THAT IM BUILDING MOVE THE RIGHT WAY. I HAVE IT SO WHEN I PRESS UP IT MOVES UP AND WHEN I PRESS LEFT AND RIGHT IT ROTATES IT LEFT AND RIGHT. IM TRYING TO FIGURE OUT HOW TO MAKE IT MOVE FORWARD IN THE DIRECTION THAT IT IS ROTATED IN. I BASICALLY CANT FIGURE OUT HOW TO MAKE IT MOVE ALONG A SLOPE… HELP ME OUT PLEASE…

Show me the money, man. Something, a fla, a piece of code, a swf.

pom :asian:

HERES MY FLASH GAME

remember trig? good stuff when you’re trying to work out slopes from rotation.

flash’s _rotation interprets rotation as somewhere between -180 and 180 (rather than 0 - 360). that plus all the trig functions expecting radians as their arguments can make things a little tricky.

but once you’ve got your head around it, it’s not so hard.

here’s some prototypes i use to create steering movies (it should really be a class, but whatever):


function enableKeyMovement(clip){
	clip.onKeyDown = function(){
		this.onEnterFrame = this["keyAction"+Key.getCode()];
	};
	clip.onKeyUp = function(){
		this.onEnterFrame = null;
	};
	clip.spd = 5;
	clip.rspd = 15;
	clip.mov = {};
	clip.setSpeeds();
	Key.addListener(clip);
	trace(clip);
};

Math.dtr = Math.PI/180;
Math.radFromRot = function(rot){
	rot -= 90;
	return (rot < 0 ? 360 + rot : rot)*Math.dtr;
};

MovieClip.prototype.keyAction37 = function(){
	this._rotation -= this.rspd;
	this.setSpeeds();
//	trace(r);
};

MovieClip.prototype.keyAction38 = function(){
	this._x += this.mov.x;
	this._y += this.mov.y;
};

MovieClip.prototype.keyAction39 = function(){
	this._rotation += this.rspd;
	this.setSpeeds();
//	trace(r);
};

MovieClip.prototype.keyAction40 = function(){
	this._x -= this.mov.x;
	this._y -= this.mov.y;
};

MovieClip.prototype.setSpeeds = function(){
	var r = Math.radFromRot(this._rotation);
	this.mov.x = Math.cos(r)*this.spd;
	this.mov.y = Math.sin(r)*this.spd;
};

then to make a clip steerable:


enableKeyMovement(movieClip);

alright, i went ahead and made it a class. plus added the ability to go forward and change directions at the same time! (ooooh!!). ; )

here’s an as file containing the SteeringClip class:

Ouhh, that’s a keeper, Supra. [SIZE=1]usual question: [/SIZE] can someone rate this thread so that we don’t lose it?

It could be a good start for a game tutorial…

pom :-\

cool a game tutorial… sounds fun… i’m in twalliewerty’s class and im makin a star fighter game… i sorta had a question… my other friend said that there was a command that loaded a movie clip directly from the library, instead of having to have it on the stage and duplicate it… i think addMovieClip or somthin… how does this work? if its even there, and if it is there, can you have movie clips in the library with actionscript already on them?

It is attachMovie you’re looking for. Check the AS dictionary.

pom :cowboy:

I have the framework of an “Asteroids” game working. I’ll post the code for that ship as soon as I can decypher my own work. Give me a couple hours.

I JUST WANT TO THANK EVERYONE THAT HAS HELPED ME AND I HAVE FINALLY GOTTEN MY SHIP TO MOVE THE RIGHT WAY

cool… I didn’t get to it, but I’m glad some of the other did. Supra and Pom are always good for a trig answer.

twalliewerty, here is your answer. It’s all in percentages, the percentage of the rotation in the current quadrant. If you want to know more ask me, but here’s your fixed game with a nice loop
for constant motion.

hey could i get a link to that SteeringClip class?