-
Using an object angle to calculate x & y values
I need to move an object forward at the angle that it's pointing. Say you want a ship to move forward based on it's angle - the ship has x and y coordinates (lets say shipx and shipy), an angle (say shipangle) and a speed (shipspeed): some maths has to be done to create a new position each time. I figured out a long-winded way of doing it but I think there should be a simple equation I don't know yet (maybe something to do with sines and copsines?).
Thanks in advance.
-
some usefull links to solve such things in future:
http://www.codylindley.com/Tutorials/trigonometry/
http://www.kirupa.com/developer/acti...igonometry.htm
http://www.adobepress.com/articles/a...p?p=30617&rl=1
http://www.albinoblacksheep.com/flash/trig
PHP Code:
function moveShip(angle){
var radians = angle* (Math.PI/180);
var speed = 2;
ship._x+= Math.cos(radians)*speed;
ship._y+= Math.sin(radians)*speed;
}
_root.onEnterFrame = function(){
moveShip(_xmouse-Stage.width/2);
}
-
Thanks for that, seems simple, I'll follow it up!
ADE
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|