My character cube falling through my maze (both have collision, I see in debug!)

Yeah, but I thought the problem might’ve come from there and tried not using the batch optimization in my early tries to fix this

This is a job for a custom mesh: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:custom_meshes

What is wrong with my approach though, why does it not work? Is it a bug?

And I don’t see how I can fit custom mesh into what I’ve done

unless you post your whole code, there is no way to find what you do wrong.

You’re right, I didn’t do the asap because I didn’t want to bother with too much code, assumed it was obvious I did some crap :stuck_out_tongue:



Here goes, it’s only 2 classes:

http://ompldr.org/vZjFodQ/Main.java

http://ompldr.org/vZjFodg/MapGen.java



I have Main where I build all the crap, and on MapGen I generate the int[][] for drawing the map on Main, don’t think there’s anything you need to know but ask away, thanks



ALSO, the drawPlayer has a little .gif character… I’ll just upload the project



http://ompldr.org/vZjFoeA/MyGame.rar

I can’t even make a simple Ping Pong game, the ball after 2 or 3 hits on raquets starts being physics immune, lol

I’ve even tried setting collision groups by hand, it keeps doing the same…

Funny it works for everybody else… In your example you set the velocity and location of the objects directly, this way you obviously don’t get proper physics results. You should do the tutorials, they explain simple mistakes like this. Also still you should use a custom mesh for your level and not combine boxes.

I found out the problem, I set the sleepingThreshold to 0, and now raquets won’t become “immune”, they were deactivating for that reason

Now though I increased ball speed a little, and it goes right through some other times (just a max of 60 linear velocity on x)

I did read all the tutorials, I made these looking at the Collision and Physics ones!



They handle setPhysicsLocation() directly in the collision one:



“Finally we put the player in its starting position and update its state – remember to use setPhysicsLocation() instead of setLocalTranslation() now, since you are dealing with a physical object.”



And they set linearVelocity() in the Physics one:



ball_phy.setLinearVelocity(cam.getDirection().mult(25));



Also, don’t take it personally as an offense to the engine, I meant that I couldn’t make a simple game refering to me not being good at it, of course :slight_smile:



(Also, sometimes the SDK starts complaining about ClassNotFound errors when I try to run the project? If I delete a blank line wherever, and then rebuild, it’ll work…)

sorry for being late to reply,



you call GeometryBatchFactory.optimize but you never store the result, thus you didnt actually call the method.



Before your code : 1112 nodes.

Ball never collided with the wall.



Now : 2 nodes

Physics: collisions with walls now happen normally as you wanted.



However: you stage is strange, after a while (0.5-1sec) the ball will fall

out of the stage, because the way you designed it,

the stage doesn’t have a ground, it is only a huge vertical wall.





i put only the changes on Main.java :

[java]

private Node scene;



public void simpleInitApp()

{

//…

playerImg = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”); // Lighting



playerNode = new Node();

rootNode.attachChild(playerNode);

map = new MapGen(40, 40);

scene = drawMap(map.getMapa());

System.out.println(scene.getChildren());

rootNode.attachChild(scene);



//…

landscapeShape = new RigidBodyControl(CollisionShapeFactory.createMeshShape(scene), 0);

scene.addControl(landscapeShape);

}



public Node drawMap(int[][] mapa)

{

Node node = new Node();

int mapaX = mapa.length;

int mapaY = mapa[0].length;

for (int i = 0; i < mapaX; i++)

{

for (int a = 0; a < mapaY; a++)

{

if (mapa[a] == 1)

{

makeSquare(node, i, a, 0.5f, 0.5f);

}

else if (mapa[a] == 2)

{

makeCube(node, i, a, 0.5f, 0.5f);

}

}

}

return (Node)GeometryBatchFactory.optimize(node);

}



public void makeSquare(Node node, int xCord, int yCord, float xSize, float ySize)

{

generationVec = new Vector3f(xCord, yCord, 0);

Box boxShape = new Box(generationVec, xSize, ySize, 0.01f);

cube[boxCount] = new Geometry(“terrainSquare”, boxShape);

TangentBinormalGenerator.generate(cube[boxCount]);

//floor.setColor(“Color”, ColorRGBA.Blue);

//floor.setTexture(“ColorMap”, assetManager.loadTexture(“Textures/RustFloor.jpg”));

floor.setTexture(“DiffuseMap”, assetManager.loadTexture(“Textures/RustFloor.jpg”));

cube[boxCount].setMaterial(floor);

node.attachChild(cube[boxCount++]);

}



public void makeCube(Node node, int xCord, int yCord, float xSize, float ySize)

{

generationVec = new Vector3f(xCord, yCord, 0.2f);



Box boxShape = new Box(generationVec, xSize, ySize, 1.2f);

cube[boxCount] = new Geometry(“wallSquare”, boxShape);

TangentBinormalGenerator.generate(cube[boxCount]);

//wall.setTexture(“ColorMap”, assetManager.loadTexture(“Textures/CaveWall.jpg”));

wall.setTexture(“DiffuseMap”, assetManager.loadTexture(“Textures/CaveWall.jpg”));

cube[boxCount].setMaterial(wall);

node.attachChild(cube[boxCount++]);

}

[/java]

1 Like

Sorry mate since my last post, I worked a few more hours trying to fix it and just abandoned the project (temporarily!), and moved on to learn about physics abit (and some other java projects)



I’ll look into it tomorrow! First of all thanks alot for coming back to me! :slight_smile:



The geometrybatch was optimizing, somehow… it’s how it’s instructed to use in the tutorials/docs, and it really was working (atleast for framerate), fully zoomed out to see the whole maze I’d get horrendous fps, around 20-50, and after optimizing, I’d get 200-300! So it was working, albeit in a poor way, going with what you said! How the heck did it have 1120 nodes though? I was only adding the cubes to rootNode O_o

I don’t remember it that well anymore… either way: if it solved the colision issues, that’s great! (I hadn’t worked on it not falling since there were no colisions at all)



Thanks again, I’ll check it tomorrow! :slight_smile:

Had a go at it now… I believe it’s still doing the same? Not sure if I did your fixes right, I sort of rushed it because I have to go… I’ll go more thoroughly tomorrow