Hi, I have problem. I’m making a moba genre game. So it’s 3x3 players per room.
each room has separated physics.
This class is making and collecting rooms:
[java]
public class GameCore extends AbstractAppState {
private ArrayList<GameWorld> worldList;
private int gwID=0;
public GameCore(Model model) {
worldList = new ArrayList<GameWorld>();
Globals.INSTANCE.getApp().getRootNode().attachChild(loader.getNode());
Globals.INSTANCE.getApp().getStateManager().attach(this);
}
public void CreateRoom(final CreateRoomM message, final HostedConnection conn) {
Globals.INSTANCE.getApp().enqueue(new Callable<Void>() {
public Void call() throws Exception {
GameWorld gw = new GameWorld( gwID++, model, loader);
worldList.add(gw);
Globals.INSTANCE.getApp().getStateManager().attach(gw);
return null;
}
});
}
public GameWorld getGameWorldById(int id) {
for (GameWorld gm : worldList) {
if (gm.getId() == id) {
return gm;
}
}
return null;
}
}
[/java]
here i have room class
[java]
private SimpleApplication app;
private BulletAppState bulletAppState;
private int id;
private ParticleController particles;
public GameWorld(int id, Model model, MapLoader loader) {
this.id = id;
bulletAppState = new BulletAppState();
}
public void initialize(AppStateManager stateManager, Application app) {
super.initialize(stateManager, app);
this.app = (SimpleApplication) app;
app.getStateManager().attach(bulletAppState);
particles = new ParticleController(bulletAppState, this);
}
[/java]
here i’m making particles:
[java]
public class ParticleController {
private RigidBodyControl shootPhy;
private BulletAppState bulletAppState;
private GameWorld gw;
public ParticleController(BulletAppState bulletAppState, GameWorld gw) {
this.gw=gw;
this.bulletAppState = bulletAppState;
}
public void addParticle(Vector3f coordinate, Quaternion pointTo, String name, float friction, float mass, float size, float acceleration, AssetManager manager, Player player, int damage, int skillType, int damageType) {
Node ballGeo = new Node("shoot");
ballGeo.setLocalTranslation(coordinate);
shootPhy = new Particle(manager, new SphereCollisionShape(size*0.1f), mass/100, gw, damage, skillType, damageType);
ballGeo.addControl(shootPhy);
shootPhy.setFriction(friction);
shootPhy.setMass(mass/100);
shootPhy.setCcdSweptSphereRadius(0.001f);
shootPhy.setCcdMotionThreshold(0.001f);
Vector3f modelFowardDir = pointTo.mult(Vector3f.UNIT_Y);
shootPhy.setLinearVelocity(modelFowardDir.mult(-acceleration));
gw.getRootNode().attachChild(ballGeo);
bulletAppState.getPhysicsSpace().add(shootPhy);
}
}
[/java]
and last my particle
[java]
public class Particle extends RigidBodyControl implements PhysicsCollisionListener, PhysicsTickListener {
private float fxTime = 0.5f;
private float maxTime = 4f;
private float curTime = -1.0f;
private float timer;
private int damage;
private int skillType;
private int damageType;
private GameWorld gw;
private Vector3f vector = new Vector3f();
private Vector3f vector2 = new Vector3f();
public Particle(AssetManager manager, CollisionShape shape, float mass, GameWorld gw, int damage, int skillType, int damageType) {
super(shape, mass);
this.gw = gw;
this.damage = damage;
this.skillType = skillType;
this.damageType = damageType;
}
@Override
public void setPhysicsSpace(PhysicsSpace space) {
super.setPhysicsSpace(space);
if (space != null) {
space.addCollisionListener(this);
}
}
@Override
public void collision(PhysicsCollisionEvent event) {
System.out.println("firing event"); <<-- PROBLEM
}
@Override
public void physicsTick(PhysicsSpace space, float tpf) {
space.removeTickListener(this);
}
}
[/java]
when client start a first world, collision is working and event is firing, but when second word is created and added in worldList, first world collision stops working, just in second world it is working and event is firing.
can someone explain this PhysicsCollisionListener behavior and help me to find solution ?
P.S. I hope i have cleaned code enough and it will be easy to read.