Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 06-15-2008, 09:39 PM   #1
Join Date: Mar 2007
Location: Big Rapids, MI
Posts: 47
Send a message via AIM to rosem
Default [AS3] Help w/ Ship Movement

Hey Everyone,

I was wondering if anyone could point me in the right direction for figuring out the movement of a ship in a game I'm building. Basically I want to ship to continuously move around on the stage, and head in whatever direction it's pointing in. Any links, etc.. would be greatly appreciated.

Any ideas?

rosem is offline   Reply With Quote
Old 06-15-2008, 09:46 PM   #2
Join Date: Mar 2007
Location: Big Rapids, MI
Posts: 47
Send a message via AIM to rosem

Actually if anyone can recommened some good tutorials or books on the subject as well, that would be great. I'm realizing that I want this thing to fly more like a plane, so it's going to need a lot of tuning...
rosem is offline   Reply With Quote
Old 06-15-2008, 11:23 PM   #3
Senior Member
lordofduct's Avatar
Join Date: Feb 2008
Location: West Palm Beach, FL
Posts: 3,872

I'm assuming you mean where pushing say up, it moves in the direction the ship is facing. left and right rotate the ship. And down moves in reverse direction of the direction the ship is pointing.

You can use a bunch of trig to pull this off, but you should always avoid trig unless necessary (sin, cos, tan... etc).

I'd use a vector... you don't have a vector class, so just use the point class or 2 variables representing 2 slots of a vector.

For Vectors there are a few things you should know that make them so great.

Vectors are denoted in math: <i,j> where i is the amount of magnitude in the x direction and j is the amount of magnitude in the y direction

A) vectors have magnitude and direction. Magnitude is the amount of "force" the vector has (hence in physics they say a vector has force and direction... not accurate though as force is a physical action... and Vectors don't have to represent physical forces). Direction is which way you are moving... it could be viewed kind of like 'slope' as well. There is no position to the vector, it is 100% free floating, which means you can apply the magnitude and direction of the vector to any object no matter where it stands.

i.e. a mass can have the force of gravity applied to it anywhere on earth... <0, -9.8> meters per second squared

B) The unit vector is a vector who has the direction, but who's magnitude is 1. These vectors can be easily manipulated because of the identity theorem (x * 1 = x). Thusly if you have a unit vector you can multiply it by any 'speed' and get a vector with that magnitude with very little work.

We use pythagorean theorem to get the unit vector.

unit vector of <i,j> = <i,j> / sqrt(i^2 + j^2)

thusly the unit vector of <5,5> is <5,5> / sqrt(50) = <.7071, .7071>


if you make a unit vector represent the direction your ship is facing you can do several things.

When updating position forward you just add the vector * speed to the position of the object. Subtract when moving backwards. And rotate the vector when turning (which does use trig as it is faster then resolving unit vectors)

here is a vector class I wrote filled with useful methods.


it could use some more tweeking to make it user friendly to most. Just keep in mind, base methods always change the vector you run the method from, static methods should be used if you want to return a new vector with out effecting the inputs.
www.lordofduct.com - come read my blog!

If you want to know how to program, take a math class, take a lot of math classes!
lordofduct is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
FlashGameLicense.com - virtual marketplace to connect game developers and buyers AdamSchroeder General Chat 0 12-18-2007 09:16 PM
[AS2] Platform Game: Smoother Vertical Movement Murphy1976 Gaming and Game Development 2 05-31-2007 11:20 PM
Rate My Game, plz fill the questioner UzumakiJr Site Check 0 12-16-2006 08:48 PM
[AS2] Game: Player movement Unknowner Gaming and Game Development 6 07-24-2006 08:28 AM
building a reaction game pyrokinesis Gaming and Game Development 3 07-22-2006 04:31 PM

All times are GMT. The time now is 06:32 PM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.