# Java Physics - Bumping

• 07-26-2005, 01:13 PM
yoha
Java Physics - Bumping
Hello! I'm programming a game, and now i'm in the part that i need to bump my player with the obstacles (the objects).
I dont really understand how to do it.

Any help will be appreciated.

thanks.
• 07-26-2005, 02:21 PM
themoffster
When I was a student, I used the following for physics routines.

Docs:
http://ocw.mit.edu/OcwWeb/Electrical...il/classes.htm
Source:
http://ocw.mit.edu/NR/rdonlyres/Elec.../0/physics.zip

Basically you need to calculate the time from impact from various surfaces and calculate the rebounds from the surface with the smallest 'time until impact'.

Read through the docs and look at the code and you should be able to figure it out.
• 07-26-2005, 02:23 PM
evlich
Collisions, most of the time, will be computed using Newtons laws. Mainly conservation of momentum and conservation of kenetic energy (depending on the type of collision). Check out
http://hyperphysics.phy-astr.gsu.edu/hbase/elacol.html
For information on inelastic and elastic collisions.

Hope this helps.
• 07-27-2005, 10:54 PM
Phaelax
What type of collision are you looking for? (AABB, OBB, full blown polygon collision)
What type of collision response are you looking for? Simply stop moving, or bounce and richochet off using proper reflections? Or perhaps you want the sliding collision seen in common FPS games like quake, where a player slides down a wall rather than stopping or bouncing off.
• 07-28-2005, 11:25 AM
yoha
all what i want is the simpelest collision - an the playe with hit something and then will stop.
• 07-28-2005, 05:26 PM
evlich
If its actually the code to detect that a collision occured, then what type of entities are you working with? If they are just rectangles then the algorithm is pretty simple, if the shapes are more complex, of course the algorithm gets a little more difficult.
• 07-28-2005, 11:06 PM
Phaelax
Probably the simpliest method is using bounding spheres. Let's say each object contains a bounding sphere class.

Code:

```    public class BoundingSphere     {         //origin of center of sphere         private float X;         private float Y;         //radius of sphere         private float radius;                 public BoundingSphere(float x, float y, float r)         {             this.setPosition(x,y);             this.setRadius(r);         }         public void setPosition(float x, float y)         {             this.X = x;             this.Y = y;         }                 public void setRadius(float r)         {             this.radius = r;         }                 public float getX()         {             return this.X;         }                 public float getY()         {             return this.Y;         }                 public float getRadius()         {             return this.radius;         }                 public boolean overlaps(BoundingSphere bs)         {             float a = this.X - bs.getX();             float b = this.Y - bs.getY();             float sqDist = a*a + b*b;             float sqRange = (this.radius + bs.getRadius())*(this.radius + bs.getRadius());                         return (sqDist < sqRange);         }     }```

Then use it somewhat like this:

Code:

```    if (ObjectA.overlaps(ObjectB))     {         ObjectA.stop();      }```
• 07-29-2005, 04:15 AM
yoha
I'll not have OVALS i'll have images, so i guess it will be squars