Hello,
I have been testing jMonkeyEngine and I’m so glad I found this community. Now I’m testing a little game/mmo using SpiderMonkey.
It’s a 3rd view “game”, where others can connect and you will see them move around.
When someone moves around, the server broadcasts a message to all the connected clients. But the problem is that I really don’t know how could I make players jump, since they are Spatials attached to the scene.
Here is the code of the “other characters” creation:
[java]public synchronized void addPlayer(final Integer id) {
AssetManager assetManager = app.getAssetManager();
Box box = new Box(new Vector3f(0, 0, 0), 1.8f, 2.8f, 1.8f);
final Geometry playerGeometry = new Geometry(“Character”, box);
Material mat1 = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
mat1.setColor(“Color”, ColorRGBA.randomColor());
playerGeometry.setMaterial(mat1);
playerGeometry.setLocalTranslation(0,1f,0);
app.enqueue(new Callable<Void>() {
@Override
public Void call() throws Exception {
rootNode.attachChildAt(playerGeometry, id);
return null;
}
});
}
[/java]
The main character is a Spatial with a CharacterControl added, so that when I want to jump “clientside” I just use player.jump();
But, How could I make the other players jump since they are just Spatials updating and moving around?
I think that I would just need some sort of jumpPlayer(final integer id) to make them jump clientside when the server broadcasts the “jump” message to all the connected clients.
[java]public synchronized void jumpPlayer(final Integer id) {
final Spatial player = rootNode.getChild(id);
app.enqueue(new Callable<Void>() {
@Override
public Void call() throws Exception {
// Something here like player.jump();
return null;
}
});
}[/java]
Thanks you so much
No one?
look at how jump() is implemented and apply the same forces
Hello, thanks for your reply
The problem is that jump() just works on a CharacterControl (which is the main character), and I wanna make jump players that are Spatials.
Should I add those Spatials a temporal CharacterControl and make them jump() and then remove that?
I’m a bit confused
The main character is created by calling:
[java] private void createCharacter() {
CapsuleCollisionShape capsule = new CapsuleCollisionShape(2f,3f);
character = new CharacterControl(capsule, 0.01f);
Box box = new Box(new Vector3f(0, 0, 0), 1.8f, 2.8f, 1.8f);
Geometry cube = new Geometry(“Character”, box);
Material mat1 = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
mat1.setColor(“Color”, ColorRGBA.randomColor());
cube.setMaterial(mat1);
model = new Node(“model”);
model.attachChild(cube);
model.addControl(character);
character.setPhysicsLocation(new Vector3f(0, 10, 0));
mainScene.attachChild(model);
getPhysicsSpace().add(character);
}
[/java]
And when I want to make the main character jump, I would call character.jump();
Thank you in advance!
if you want, but is there a reason why they can’t just have a CharacterControl permanently to begin with? if you want to do it your way, its better to use control.setEnabled(true/false), instead of recreating it everytime
Hello! I will try what you told me… But one question, How can I call the getPhysicsSpace() from bulletAppState that is defined in the Main java class?
you can create a getter function for it in your Main class.
[java]public BulletAppState getBulletAppState() {
return bulletAppState;
}[/java]
Thank you for your response! I finally got It working