What have I collided with?

Hi,



What I need is a first person game, and whenever the player walks into an object in the scene I need to output what that something is. For example, if the player walks into a chair, I need to be able to save that they have walked into a chair. If they have walked into a tree, I need to store that they have walked into a tree etc etc.



I have set up a statistics class for this, but don't know how to generate collision events so that I can send them to the statistics class.



One other issue is that if the player walks into a tree, and remains in contact with the tree, it should only register as one collision. Not one collision every time the scene updates.



Thanks for your help in advance!



Chris.

I would assume you looked at the classes under jmetest.intersection?



also, to solve your problem of you only want to register as one collision, have a boolean and if boolean is false and collision is true, set boolean true and do what you want to do with your collision.



if boolean is true and collision is true, than dont do anything because you have already collided, but once collision stops (collision = false) then set boolean back to false.



as far as different types of collisions (IE: chair collision, tree collision, etc) I am sorry but I havent started working with collisions yet, so I cant really help you. However, in the jmetest.intersection.TestPick.java there is a system in there where a ray interesection crossing an object outputs differently for different objects. It might be useful for you.



When you run it, notice what happens when you click on the lines, the guys face, or the guys body. (IE: sort of collision detection, and also different collision)

I would make one helper class,

with a pointer to your "player",

and a list holding the "collidables".



This class should have methods for adding and removing "collidables".



Then it should have a 'void update(float time)' method,

wich looks like this:

(I suppose you have a Map<Spatial, Boolean> collidables)


public void update(float time) {
   for(Spatial s : collidables.keySet()) {
     // use true for triangle accurate collisions, but i think bounding collisions are enough ;)
      if(player.hasCollisions(s, false)) {
          if(!collidables.get(s)) { // if it hasn't already been tracked..
            // perform your action here ;)
          }
       } else {
          collidables.put(s, false);
       }
   }
}



Something like that ;)

Tim8dev

Edit: Had a few null point exception problems but I have sorted them now.