Home > Library > Calculate X and Y velocity

Calculate X and Y velocity

November 20th, 2008

Calculate the x and y velocities based on an angle and speed

Download zip

onMouseDown = function () {
angle = Math.floor(Math.random()*-90);
//angle=30
speed = 200
//speed = Math.floor(Math.random()*30)+30;
radians = angle/180*Math.PI;
xspeed = Math.cos(radians)*speed;
yspeed = Math.sin(radians)*speed;
// draw lines to represent distances
rotline.innerline._width = speed;
rotline._rotation = angle;
p1x = rotline._x;
p1y = rotline._y;
p2x = rotline._x;
p2y = rotline._y;
this.createEmptyMovieClip(”line”, 1);
line.lineStyle(5, 0xffffff, 30);
line.moveTo(p1x, p1y);
line.lineTo(p1x+xspeed, p1y);
line.moveTo(p1x+xspeed, p1y);
line.lineTo(p1x+xspeed, p1y+yspeed);
};

  1. No comments yet.
  1. No trackbacks yet.