I made a little “game” with a world of boxes (a little bit like minecraft) and I would make it so that gravity will affect to the player and the player will collide with the other cubes.
I tried to solve it with PhysicsRigidBody and PhysicsCharacter, but it didn’t work.
I haven’t got more ideas how it would work.
Does anybody know? Thanks in advance.
PS: Sorry for the bad English!
create a new “TestGame” project in jmp and look at the physics tests.
I solved this problem, but I have a new one:
I want that the player rotates if you move the mouse it does already work that the camera rotates if you move the mouse, but how can I rotate the player (it’s a PhysicsCharacter)?
Does anybody know? Thanks in advance.
PS: Sorry for the bad English!
you have to use something like:
player.lookAt(camera.getDirection());
teddybraun said:
I solved this problem, but I have a new one:
I want that the player rotates if you move the mouse it does already work that the camera rotates if you move the mouse, but how can I rotate the player (it's a PhysicsCharacter)?
Does anybody know? Thanks in advance.
PS: Sorry for the bad English!
You could to implement something like "ActionListener" and to register the mouse actions on "inputManager". After that rotate the player in action listener implementation's method "inAction" or something like.
There is no rotation or lookAt method for PhysicsCharacters, that’s the problem. And how can I rotate it without rotate or lookAt method?
Does anybody know? Thanks in advance.
PS: Sorry for the bad English!
characterControl.setViewDirection(cam.getDirection());
Setekh said:
characterControl.setViewDirection(cam.getDirection());
But how can I attach the CharacterControl to my PhysicsCharacter or the PhysicsCharacter to the CharacterControl?
Does anybody know? Thanks in advance.
PS: Sorry for the bad English!
I thought, I found a solution, but whyever it doesn’t work, you can move the camera but if you press “w”, “a”, “s” or “d” key, nothing happens.
that’s my code to attach the keys:
[java]private void initKeys() {
inputManager.addMapping(“Lefts”, new KeyTrigger(KeyInput.KEY_A));
inputManager.addMapping(“Rights”, new KeyTrigger(KeyInput.KEY_D));
inputManager.addMapping(“Ups”, new KeyTrigger(KeyInput.KEY_W));
inputManager.addMapping(“Downs”, new KeyTrigger(KeyInput.KEY_S));
inputManager.addMapping(“Jumps”, new KeyTrigger(KeyInput.KEY_SPACE));
inputManager.addListener(this, “Lefts”);
inputManager.addListener(this, “Rights”);
inputManager.addListener(this, “Ups”);
inputManager.addListener(this, “Downs”);
inputManager.addListener(this, “Jumps”);
}
public void onAction(String name, boolean value, float tpf) {
if (name.equals(“Pause”)) {
isRunning = !isRunning;
}
if (name.equals(“Up”)) {
up = value;
}
if (name.equals(“Down”)) {
down = value;
}
if (name.equals(“Right”)) {
right = value;
}
if (name.equals(“Left”)) {
left = value;
}
}[/java]
And that’s the code to make the movement:
[java]@Override
public void simpleUpdate(float tpf) {
Vector3f v = player_rb.getPhysicsLocation();
Vector3f camDir = cam.getDirection().clone().multLocal(0.6f);
Vector3f camLeft = cam.getLeft().clone().multLocal(0.4f);
walkDirection.set(0, 0, 0);
if (left) { walkDirection.addLocal(camLeft); }
if (right) { walkDirection.addLocal(camLeft.negate()); }
if (up) { walkDirection.addLocal(camDir); }
if (down) { walkDirection.addLocal(camDir.negate()); }
//player_rb.setWalkDirection(walkDirection);
player_rb.setPhysicsLocation(new Vector3f(v.x + walkDirection.x, v.y, v.z + walkDirection.z));
cam.setLocation(player_rb.getPhysicsLocation());
//cam.setLocation(player.getPhysicsLocation().add(0.4f,0.75f,0));
}[/java]
Why it doesn’t work, what’s th eproblem? And what’s the solution for it?
Does anybody know? Thanks in advance.
PS: Sorry for the bad English!
look into the tests in bullet, TerstWalkingChar.java
I solved it, I was so stupid:
In the first part I wrote “Ups”, “Lefts”, “Rights” and “Downs” and in the second part I wrote “Up”, “Left”, “Right” and “Down”.
PS: Sorry for the bad English!
I have a new problem, I want that the player can add or remove cubes (like in minecraft) if the player clicks on one face of the cube. And the created cube should be on the side where the player clicked the cubes face, and if he removes a cube it should be this one the player clicked. How can I do this?
Does anybody know? Thanks in advance.
PS: Sorry for the bad English!
First thing, no box based game makes its meshes out of boxes. This sounds kind of counter-intuitive but think about it: You seldom see a complete box, you only see its upside or maybe the upside and two sides. So what happens is that the games actually create one mesh that represents the surface as it looks when you combine lots of boxes. So what you need to do is think of a logic how you can create and change such a mesh with the data you have.
Is there no function to get the cubes face/plane the player clicked? And if not, how could I do this else?
Does anybody know? Thanks in advance.
PS: Sorry for the bad English!
For a (thought) array of cubes is pretty easy to determine what block has been clicked by getting the picking coordinates isn’t it?
How can I find out which side the player clicked? I tried to make it with the position of the clicked cube and the collision point, but it didn’t work.
Does anybody know? Thanks in advance.
PS: Sorry for the bad English!
Again, its boxes. With the location of the collision you can easily determine that.
First: I get the cubes position and the collision position
Second: I test for x, y and z of collision poisiton if it’s more or less than cubes position
Third: I update the array and switch at the right position the 0 (for no cube) to a 1 (for cube)
Fourth: I update the position and create the new cube
But there’s an error:
Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.ArrayIndexOutOfBoundsException: 6
what’s the problem?
Does anybody know? Thanks in advance.
PS: Sorry for the bad English!
teddybraun said:
But there's an error:
Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.ArrayIndexOutOfBoundsException: 6
It's the next lines that you left out that are kind of important. An exception without a stack trace is only 25% useful or so. ;)
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_picking
will help you learn the position of the click, and what user clicked.