Ok, Hi all. This is my first post.
Phys2d lib is wonderful but there’s something that I couldnt manage yet. How to perform a collision ?
I know how to detect a collision when two bodies touch using Arbiter, Contact classes.
I can list the bodies, the point of collision, but how do I apply movement to body2 when body1 touches it ? I am making an “AirHockey” game.
This is my first attempt which of course does not work (I wouldnt be here asking for help, hehe)
I thought I could use static method collide but I think I am not invoking it the right way because nothing happens. Note that body1/body2 must be the pusher/puck (there are other bodies in the world, “the walls”).
public void detectsColision(){
Body body1 = null;
Body body2 = null;
ArbiterList arbs = world.getArbiters();
Arbiter arb = null;
if(arbs.size() > 0){
for(int i=0;i<arbs.size();i++){
arb = arbs.get(i);
int numContacts = arb.getNumContacts();
if(numContacts > 0){
Contact[] Contacts = arb.getContacts();
Vector2f punto = (Vector2f)Contacts[0].getPosition();
body1 = arb.getBody1();
body2 = arb.getBody2();
System.out.println("BODY1: “+body1+” BODY2: "+body2);
if(body1.equals(this.puck) && body2.equals(this.pusher) ||
(body1.equals(this.pusher) && body2.equals(this.puck)))
Collide.collide(Contacts, this.puck, this.pusher,1000);
}
}
}
Also, the harder the collision, the higher the speed of the puck, I have no idea how to implement that.
I appreciate your help.