View Full Version : I Need Help On Action Scripting
twalliewerty
October 16th, 2002, 03:14 PM
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...
pom
October 16th, 2002, 03:19 PM
Show me the money, man. Something, a fla, a piece of code, a swf.
pom :asian:
twalliewerty
October 16th, 2002, 07:33 PM
HERES MY FLASH GAME
sbeener
October 16th, 2002, 08:30 PM
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);
sbeener
October 16th, 2002, 09:41 PM
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:
pom
October 17th, 2002, 05:52 AM
Ouhh, that's a keeper, Supra. usual question: can someone rate this thread so that we don't lose it?
It could be a good start for a game tutorial...
pom :-\
Scootman
October 17th, 2002, 11:09 PM
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?
pom
October 18th, 2002, 06:18 AM
It is attachMovie you're looking for. Check the AS dictionary.
pom :cowboy:
upuaut
October 18th, 2002, 07:46 AM
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.
twalliewerty
October 18th, 2002, 01:11 PM
I JUST WANT TO THANK EVERYONE THAT HAS HELPED ME AND I HAVE FINALLY GOTTEN MY SHIP TO MOVE THE RIGHT WAY
upuaut
October 18th, 2002, 02:39 PM
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.
seanWylieToal
October 20th, 2002, 07:41 PM
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.
akademik
August 7th, 2004, 11:16 AM
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:
hey could i get a link to that SteeringClip class?
RyxiaN
December 21st, 2004, 10:30 AM
I wanna learn to. But i didn't understand
GPP
August 19th, 2005, 05:16 PM
Confused :(
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.