Home > Basics > Example1

Example1

February 23, 2012 Leave a comment Go to comments

v_mag = 5
v_ang = 0

c.onPress = function(){
c.startDrag()
}
c.onRelease = function(){
c.stopDrag()
}

b.onEnterFrame = function(){
dist = Pythagoras(b._x, b._y,c._x, c._y)
if(dist > 100){
v_ang = getAngle(b._x, b._y,c._x,c._y)
vx = v_mag*Math.cos(v_ang)
vy = v_mag*Math.sin(v_ang)

b._x += vx;
b._y += vy;
}
}

function getAngle(x1, y1,x2, y2):Number{
distX = x2-x1
distY = y2-y1
ang = Math.atan2(distY, distX)
return ang
}

/*b.onPress = function(){
b.startDrag()
}
b.onRelease = function(){
b.stopDrag()
}
b.onEnterFrame = function(){
//min = (b._width +c._width)*0.5
//dist = Pythagoras(b._x, b._y,c._x, c._y)

if(){
c._x += 1
}
}
*/
function Pythagoras(x1, y1,x2, y2):Number{
distX = x2-x1
distY = y2-y1
z = Math.sqrt(distX*distX + distY*distY)

return z
}

Advertisements
Categories: Basics
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: