-
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.
-
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.
-
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.
~evlich
-
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.
-
all what i want is the simpelest collision - an the playe with hit something and then will stop.
-
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.
~evlich
-
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();
}
-
I'll not have OVALS i'll have images, so i guess it will be squars
Similar Threads
-
Replies: 2
Last Post: 06-14-2006, 03:16 PM
-
Replies: 1
Last Post: 05-13-2005, 06:46 AM
-
By Rob Abbe in forum Talk to the Editors
Replies: 44
Last Post: 01-13-2003, 02:57 PM
-
By Mike Tsakiris in forum .NET
Replies: 11
Last Post: 10-04-2002, 05:32 PM
-
By JJ in forum Enterprise
Replies: 1
Last Post: 07-06-2000, 04:50 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|