sorry for not explaining to well what i was trying to achieve…

those tutorials are the basickind of gravity where the pull is only downwards. the gravity im looking for is between two objects in space with different masses. does that explain it better?

And the force applied to ball2 is simply the opposite

I’ve tried to do that kind of things a long time ago, and you’ll probably have to change the numbers quite a few times before you can get something that works properly.

because it just does the same thing as what i had… the ball accelerates towards the other ball but once it passes it, it just keeps accelerating rather than slowing down and returning… i hope that explains what’s happening…

right now i just want one ball (ball1) to gravitate towards ball2 which is stationary. this is the script that i have… :
[AS]G = 3
m1 = 1
m2 = 1
ball1.onEnterFrame = function() {
this.diffx = ball2._x-this._x;
this.diffy = ball2._y-this._y;
this.vx += (Gm1m2)/this.diffx;
this.vy += (Gm1m2)/this.diffy; // speed
this.dx += this.vx;
this.dy += this.vy; // motion
this._x += this.dx;
this._y += this.dy;
};[/AS]

i didn’t think this would cause me so much trouble… there must be something wrong with the formula… next year after i have taken physics i’ll know how to fix this… for now, does anybody else know any physics and see anything wrong with the forumlas?

i was trying to adjust it so it knows which direction its going
and make it reach a point and reverse
other wise., you had no bounds for it, and were adding to its _x
and _y with each frame at an increasing velocity with increased
distance

I got it working !! this is fuuuun stuff. look at this…
[AS]
gravitate= function(ball1,ball2) {
var diffx = (ball1._x-ball2._x);
var diffy = (ball1._y-ball2._y);
var dist = Math.sqrt(diffxdiffx+diffydiffy);
var d = (Gball1.m)/(distdist); //force
var a = Math.atan2(diffy,diffx);
var ax = dMath.cos(a);
var ay = dMath.sin(a); // acceleration
ball2.vx += ax;
ball2.vy += ay; // motion
ball2.dx += ball2.vx;
ball2.dy += ball2.vy; //postition
ball2._x = ball2.dx;
ball2._y = ball2.dy;
}
go=function(){
for(var i=0;i<16;i++)
{
gravitate(ball1,ball2);
/comment this line (//)
gravitate(ball3,ball1);
gravitate(ball3,ball2);
gravitate(ball2,ball1);
gravitate(ball2,ball3);
gravitate(ball1,ball3);
///
}
}
G=1;

its a really finicky formula… one bad variable and the balls just fly off the screen! Severe tweaking proved to be the only remedy, but the end result is worth it.

messed with it some more
somewhat based on the gravity tutorial here flash5
on the stickman

onClipEvent (load) {
// gravity is what I called g in the tutorial. The
// higher g the harder the ball will fall.
// gravity = 0 can be set, as an experiment, but
// it will in fact create a "zero gravity" effect
// gravity < 0 will create an inverted gravity effect
gravity = 3 ;
// This sets the _y position of the floor
floor = _root.ball._x ;
floorx1 = _root.ball._x-this._width ;
floorx2 = _root.ball._x+this._width ;
// Bounce is a number < 1 but close to 1
// The closer to 1, the higher the ball will bounce
bounce = 0.94 ;
// We set the speed of the ball when it is released.
speedx = 0 ;
speedy = 0 ;
}
onClipEvent (enterFrame) {
if (pressing) {
// if we are pressing
// drag the object
startDrag (this,true) ;
// calculate the speed
speedx = this._x - x0 ;
speedy = this._y - y0 ;
// set a new reference point
x0 = this._x ;
y0 = this._y ;
} else {
floor = _root.ball._x ;
floorx1 = _root.ball._x-this._width ;
floorx2 = _root.ball._x+this._width ;
stopDrag () ;
speedy = speedy + gravity ;
this._x += speedx/5 ;
this._y += speedy/5 ;
if (this._y > floor) {
this._y = floor ;
speedy *= -bounce ;
}
if (this._x < floorx1) {
this._x = floorx1 ;
speedx *= -bounce ;
}
if (this._x > floorx2) {
this._x = floorx2 ;
speedx *= -bounce ;
}
// soup squish ball on walls
// squish is relative to speed along coresponding axis
if (this._y == floor) {
this._yscale = 15-Math.abs(speedy/10);
} else if (this._y<floor) {
this._yscale = 15;
}
if (this._x == floorx1 or this._x == floorx2) {
this._xscale = 15-Math.abs(speedx/10);
} else if (!this._x == floorx1 or !this._x == floorx2) {
this._xscale = 15;
}
// end soup
}
}

on the red ball

onClipEvent (load) {
// gravity is what I called g in the tutorial. The
// higher g the harder the ball will fall.
// gravity = 0 can be set, as an experiment, but
// it will in fact create a "zero gravity" effect
// gravity < 0 will create an inverted gravity effect
this.gravity = 2 ;
// This sets the _y position of the floor
this.floor = 375 ;
this.floorx1 = 0 ;
this.floorx2 = 525 ;
// Bounce is a number < 1 but close to 1
// The closer to 1, the higher the ball will bounce
this.bounce = 0.99 ;
// We set the speed of the ball when it is released.
this.speedx = 0 ;
this.speedy = 0 ;
}
onClipEvent (enterFrame) {
if (this.pressing) {
// if we are pressing
// drag the object
startDrag (this,true) ;
// calculate the speed
this.speedx = this._x - this.x0 ;
this.speedy = this._y - this.y0 ;
// set a new reference point
this.x0 = this._x ;
this.y0 = this._y ;
} else {
stopDrag () ;
this.speedy = this.speedy + this.gravity ;
this._x += this.speedx/5 ;
this._y += this.speedy/5 ;
if (this._y > this.floor) {
this._y = this.floor ;
this.speedy *= -this.bounce ;
}
if (this._x < this.floorx1) {
this._x = this.floorx1 ;
speedx *= -this.bounce ;
}
if (this._x > this.floorx2) {
this._x = this.floorx2 ;
speedx *= -this.bounce ;
}
// soup squish ball on walls
// squish is relative to speed along coresponding axis
if (this._y == this.floor) {
this._yscale = speedy/2;
} else if (this._y<this.floor) {
this._yscale = 100;
}
if (this._x == this.floorx1 or this._x == this.floorx2) {
this._xscale = speedx/2;
} else if (!this._x == this.floorx1 or !this._x == this.floorx2) {
this._xscale = 100;
}
// end soup
}
}