Java Physics - Bumping

 DevX Home Today's Headlines   Articles Archive   Tip Bank   Forums

# Thread: Java Physics - Bumping

1. Registered User
Join Date
Jul 2005
Posts
3

## 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.

2. Registered User
Join Date
Oct 2004
Posts
3
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.
Last edited by themoffster; 07-26-2005 at 02:26 PM.

3. Registered User
Join Date
Aug 2003
Posts
313
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.

4. Senior Member
Join Date
Mar 2004
Posts
635
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.

5. Registered User
Join Date
Jul 2005
Posts
3
all what i want is the simpelest collision - an the playe with hit something and then will stop.

6. Registered User
Join Date
Aug 2003
Posts
313
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.

7. Senior Member
Join Date
Mar 2004
Posts
635
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;

public BoundingSphere(float x, float y, float r)
{
this.setPosition(x,y);
}

public void setPosition(float x, float y)
{
this.X = x;
this.Y = y;
}

{
}

public float getX()
{
return this.X;
}

public float getY()
{
return this.Y;
}

{
}

public boolean overlaps(BoundingSphere bs)
{
float a = this.X - bs.getX();
float b = this.Y - bs.getY();
float sqDist = a*a + b*b;

return (sqDist < sqRange);
}
}```

Then use it somewhat like this:

Code:
```    if (ObjectA.overlaps(ObjectB))
{
ObjectA.stop();
}```

8. Registered User
Join Date
Jul 2005
Posts
3
I'll not have OVALS i'll have images, so i guess it will be squars

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 FAQ Latest Articles Java .NET XML Database Enterprise