ForumsProgramming Forumball bounce off objects

0 3537
staticzone
offline
staticzone
67 posts
Nomad

Hey guys, i was wondering how do you make a movie clip bounce off another movie clip, heres my script and its not working for some reason,
onClipEvent(load) {
var dragging:Boolean = false;
var vel:Object = { x: 0, y: 0 };
var pos:Object = { x: _x, y: _y };
var old:Object = { x: _x, y: _y };
var radius:Number = this._width / 2;
var movie:Object = _root.MovieClip.mc_shape;
}

onClipEvent(enterFrame){
if( !dragging ) {
vel.y += _root.gravity;

pos.x += vel.x;
pos.y += vel.y;

if( pos.y + radius > movie.height ) {
pos.y = movie.height - radius;
vel.y *= -_root.restitution;
vel.x *= _root.friction;
}

if( pos.x + radius > movie.width ) {
pos.x = movie.width - radius;
vel.x *= -_root.restitution;
}

if( pos.x < radius ) {
pos.x = radius;
vel.x *= -_root.restitution;
}

_x = pos.x;
_y = pos.y;

} else {
old.x = pos.x;
old.y = pos.y;
pos.x = _x;
pos.y = _y;

vel.x = ( pos.x - old.x ) / 2;
vel.y = ( pos.y - old.y ) / 2;
}
}

plz help

  • 0 Replies
Showing 1-0 of 0