How to block house?

I import model houses from 3ds max

but my player can walk through them.

How to set to block house ?

I don’t understand about collision  :’( please teach me.

my code

public void buildHouse(String name,String file) {
    Node model = null;
        try {
        MaxToJme C1 = new MaxToJme();
        ByteArrayOutputStream BO = new ByteArrayOutputStream();
            URL maxFile = Level3.class.getClassLoader().getResource(file);
            C1.convert(new BufferedInputStream(maxFile.openStream()),BO);
            model = (Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
        model.setModelBound(new BoundingBox());
    } catch (IOException e) {
                    .throwing(this.getClass().toString(), "buildPlayer()",

private void buildVillage() {
        //Create house
    n2 = new Node("Node 2 for collision");
        Village village1 = new Village();
        village1.setLocalTranslation(new Vector3f(70,-1.83f,70));

my output

please do not post more than once. read on here.

or u can use physics to solve this by attaching the house model to a static physics node.

It is possible to detect collisions with Spatial.findCollisions, handling collisions is more difficult, for that you need to consult HamsterofDeath who is an expert.

Thank you for answer I try to solve with collision but it not work.(It show nonpointer exception  :’( )

please show me some code. :slight_smile: If you can attach house model

thank you

It would be great if you explained more about that Null Pointer Exception you got. Where in the code, what object was null if possible.

I think you will welcome a more higher level explanation (please ignore the post if all this is too obvious for you).

I supposse you are using one of the built-in controllers to move around.

Note that drawing models and geometry is different than actually interact with them.

To interact with your geometry, you need to handle all manually. This means that if you try, i.e., to make a character walk, you will need to define how width and tall your character is, and find whether it is colliding with your geometry.

A usual method to achieve this is to use a bounding box for your character, and use collitions to find if your character has collided with any of your object. If it did, you move it back to the last valid position (this is a really uncomplete method though).

However, what I have said applies to floor too.

  • So, how is your character standing on the floor? what are you doing to make it not able to go through it?
  • How are you moving your character (using a controller?)

    A more advanced, but in the same time handy method of handling all this is to use a physic engine that manages collisions for you. A physic engine can make sure your objects never go through each other. However, start replying to the questions above so we can try to help you better.

Momoko_Fan said:

It is possible to detect collisions with Spatial.findCollisions, handling collisions is more difficult, for that you need to consult HamsterofDeath who is an expert.

*happy happy joy joy*

there are several ways to solve collisions.
the easy and low budget way:
if there is a collision, reset the position of your character to its last one. this one is ugly. you might still get through walls on low framerates.

the acceptable way for non FPS games and solid walls (no small obstacles like chairs or non-solid-but-blocking-walls like a wall containing small holes:
shoot a ray in the direction you're heading. if there is a collision, reset your position to the intersection point between the ray and the world. i'm doing this to keep the fast moving projectiles in hhexen from beaming through walls.

the easy and "this feels right" way:
if you only use boxes (oriented or not), you just have to move your character along the boxes normal until it's outside. the calculation is quite simple - just check which way is the shortest, add a rotation in case you're using OBBs.
this way, if you run into a box, you'll slide along it's border, your speed depending on the angle. maybe this suits your needs.

the hamsterofdeath way:
collect all triangles the players bounding box is touching and move the player along their normals (shortest first, check for collisions again, repeat) until all collisions are handled. this *may* sound easy, but it's not ;)
there a lot of special cases, "player squished" detection, unsolvable situation detection, stair detection, not to mention special meshes like ladders and moving meshes like doors.