| View previous topic :: View next topic |
| Author |
Message |
Solar42693

Joined: 11 Jul 2006 Posts: 35
|
Posted: Thu Jul 13, 2006 12:32 am Post subject: anyone have a code that makes an object move in 8 directions |
|
|
i've tried 3 or 4 but i couldn't get any to work right
thanks |
|
| Back to top |
|
 |
|
|
Samuel Rounce 100+ Club

Joined: 30 Oct 2005 Posts: 116 Location: London, UK
|
Posted: Sat Jul 15, 2006 2:13 am Post subject: Re: anyone have a code that makes an object move in 8 directions |
|
|
| Explain it better and I may be able to help you, I normally can as long as I know what you're talking about. |
|
| Back to top |
|
 |
Solar42693

Joined: 11 Jul 2006 Posts: 35
|
Posted: Sat Jul 15, 2006 4:48 pm Post subject: Re: anyone have a code that makes an object move in 8 directions |
|
|
| Explained Better: Do you have an actionscript code i can apply to a movieclip to make it rotate, face, and move in 8 directions by using the arrow keys, up to go forward in the direction your facing, right to rotate to the right, left to rotate to the left, and down to go backwards from the direction your facing. Like a spaceship or something. |
|
| Back to top |
|
 |
Solar42693

Joined: 11 Jul 2006 Posts: 35
|
|
| Back to top |
|
 |
Samuel Rounce 100+ Club

Joined: 30 Oct 2005 Posts: 116 Location: London, UK
|
Posted: Sat Jul 15, 2006 6:48 pm Post subject: Re: anyone have a code that makes an object move in 8 directions |
|
|
Although I'd rather write a post walking you through how to do this, I've never tried flash game programming so I'm not too sure myself but a quick google around got me:
http://www.adobe.com/devnet/flash/articles/asteroids.html
That should contain what you were after.
I don't mean any offence here but you seem pretty new to flash and actionscript, I recommend getting a book or doing beginner tutorials for the basics rather than just copying and pasting code and not fully knowing what all of it does. |
|
| Back to top |
|
 |
Solar42693

Joined: 11 Jul 2006 Posts: 35
|
Posted: Sun Jul 16, 2006 1:17 am Post subject: Re: anyone have a code that makes an object move in 8 directions |
|
|
| Thanks for the site, and about the beginner tutorials thing, I've done most of those. It's moving on to the intermediate tutorials that's the problem lol. |
|
| Back to top |
|
 |
Solar42693

Joined: 11 Jul 2006 Posts: 35
|
Posted: Sun Jul 16, 2006 6:36 pm Post subject: Re: anyone have a code that makes an object move in 8 directions |
|
|
After cutting down the code from that website here's the code for anyone else that wants it. Just create a movieclip and give it an instance name of ship.
| Code: |
function makeShip (){
ship.angle = 0;
ship.xv = 0;
ship.x = 0;
ship.y = 0;
ship.yv = 0;
ship.xa = 0;
ship.ya = 0;
ship.v = 0;
ship.visc = 0.02;
ship.drag = 0;
mp = Math.PI, mpow = Math.pow, msr = Math.sqrt;
ship.onEnterFrame = function() {
if (Key.isDown(Key.RIGHT)) {
this.torque = 5;
} else if (Key.isDown(Key.LEFT)) {
this.torque = -5;
} else {
this.torque = 0;
}
this.rtorque = 0.5*this.AngVelocity;
this.AngAcceleration = this.torque-this.rtorque;
this.AngVelocity += this.AngAcceleration;
this.angle += this.AngVelocity;
if (this.angle<0) {
this.angle += 360;
}
if (this.angle>360) {
this.angle -= 360;
}
this.v = msr(mpow(this.xv, 2)+mpow(this.yv, 2));
this.drag = this.visc*this.v;
if (Key.isDown(Key.UP)) {
this.force = 1;
} else {
this.force = 0;
}
this.xa = ((this.drag*this.xv)*-1)+(this.force*Math.sin(mp/180*this.angle));
this.ya = ((this.drag*this.yv)*-1)-(this.force*Math.cos(mp/180*this.angle));
this.xv += this.xa;
this.yv += this.ya;
this._y += this.yv;
this._x += this.xv;
this._rotation = this.angle;
};
}
function Game() {
doo = new makeShip();
}
foo=new Game();
|
Apply this to the actionscript on the keyframe, not on the actual mc. |
|
| Back to top |
|
 |
|