im experimenting with gravity wells right now and have hit a snag.
if i want the wells radius to be larger then the wells force, then if then this happens to the object:
withing certain radius it will pull the object( just what i want ).
to fat, and it will push the object( now what i want. )
here is the code for pulling the object
Vector2 GravityWell( Vector2 Well, float radius, float WellStrength, Vector2 ObjectPosition, float DeltaTime )
{
Vector2 Acceleration;
Vector2 B( Well.X, Well.Y );
Vector2 normalized( B - ObjectPosition );
normalized.Normalize();
Vector2 dir( ObjectPosition - B );
dir.Normalize();
float diff_X = B.X - ObjectPosition.X;
float diff_Y = B.Y - ObjectPosition.Y;
float distance = sqrt( diff_X * diff_X + diff_Y * diff_Y );
if( distance < radius )
{
float r = radius;
float s = WellStrength;
float s_s = r / WellStrength;
Acceleration.X -= ( dir.X * ( ( WellStrength * s_s ) - distance ) ) * DeltaTime;
Acceleration.Y -= ( dir.Y * ( ( WellStrength * s_s ) - distance ) ) * DeltaTime;
}
return Acceleration;
}
the WellStrength variable is supposed to be the speed at wich it pulls the object ( the closer the object is to the center of the well the more force the wel exerts on the object )
how would i use the stregth variable so that when the radius is larger, the pull is smaller ?
here is a diagram of whats happening
[attachment=6147:diagram.jpg]
Thanks In Advance.