Im looking for some help please.
Im doing a simple Java game (well for the Android smart phone actually), and Id like to implement some gravitational slingshot effect in my game. The way it will work is as follows:
An emitter emitts a steady stream of particles in random directions and at a constant velocity. At a random position on the screen, there is a "Gate". A Gate is simply a immovable stationary object that does nothing except register when a particle should collide with it.
But I want my particles to be "attracted" to the Gate when they come within a certain radius from the gate (before the main collision occurs). This attraction should be like a satellite geting sling shot past a planet (NASA calls it gravity assist). The particles can either be sling shot past, or if they collide with the gate, the score will be incremented.
Does anyone know of a good tutorial/ suggestion for this?
Here is some code that I have tried so far but there is an error somewhere as nothing happens when a particle gets close to the Gate. They simply continue on their original path.
Here I detect a collision, and then call the Particle class' calcGravPull() method
if (getDistanceBetweenObjects(gate.getX(), particle[i].getX(), gate.getY(), particle[i].getY()) <=
sumOfRadii(particle[i].getRadius(), barrier.getRadius()) + barrier.getOuterCollisionRadius())
getDistanceBetweenObjects(gate.getX(), particle[i].getX(), gate.getY(), particle[i].getY()));
And here is the method to do the movement
public void calcGravPull(int mass1, int mass2, double distBetweenObjects)
gravityPull = GRAV_CONSTANT * ((mass1 * mass2) / (distBetweenObjects * distBetweenObjects));
x += gravityPull;
y += gravityPull;