How to use PhysicsCollisionListener?


#21

If first collision with this object, change score.

What is difficult about that logic?


#22

Take a look at this example:
https://github.com/jMonkeyEngine/jmonkeyengine/blob/master/jme3-examples/src/main/java/jme3test/games/RollingTheMonkey.java


#23

I do not know how to know when it’s the first collision, I do not know how to get that parameter


#24

OK, thank you very much, I’ll look at it.


#25

It’s not a parameter. It’s your game, your code, your state that you keep track of.

Make a field on the object. Set it to true when it first collides and change the score. If that field is true already then don’t change the score.


#26

Is that just like this function every time it ends it is destroyed, even if I use a boolean it is destroyed and it is created many times, therefore if I use that boolean in the function simpleUpdate to verify I always have the same result … it is always the same thing I get as a result, a score greater than 8 and multiply that by 8 times … XD
Google translator

 public void collision(PhysicsCollisionEvent objetoColisionado)

#27

Your objects are involved in the collision. You can set fields on those objects.


#28

I think that this is the solution I am going to dedicate some time to this code. Thanks


#29

Is there anything in the documentation related to this that you name =?


#30

I mean, it’s basic Java.

if( !myObject.getTheFieldThatIDefine()  ) {
    myObject.setTheFieldThatIDefine(true);
    incrementScore();
}

The event object has your objects in it. Those are your objects that you defined. Either a custom class or a spatial or something. For your own classes, just define the fields. Basic Java programming. For Spatial, you can use setUserData() for the same thing.


#31

OK, I’m going to try it … I’m going to think about all the information they gave me and I’m going to ask you again any … thank you very much for your time