I came back to an old project after almost a year, tinkered a bit with it and somehow messed up the firing of my cannon!
When firing the cannon (By pressing space and having the input manager react) the ball is obviously supposed to exit the cannon muzzle, but the cannonball (a regular jmonkey sphere) is offset by quite a lot. In addition, two faces of the sphere, one in the “front” and one in the “back”, are not offset and remain roughly where the ball is supposed to be. Theses faces, however, are shrunk down into single points, which makes it appear as if the sphere has two long spikes protruding in front of it.
I cross-referenced the old and new version through GitHub and nothing major changed that I think could have an effect.
Creating a cylinder instead of a sphere when firing works perfectly fine. But not a Box, however the box will not have spikes, only offset.
Creating a sphere in the init places it correctly, without any spikes or offsets. Same for boxes.
Thus this is obviously contained in the ActionListener somehow, althouth I have no idea why or how to solve it.
Shortened code:
private ActionListener actionListener = new ActionListener()
{
public void onAction(String name, boolean keyPressed, float tpf)
{
if (keyPressed && time > 0)
{
if (name == "fire")
{
Geometry cBall = geos.createcannonball(player.getLocalRotation(), player.getChild("cannonballStartNode").getWorldTranslation());
cannonballNode.attachChild(cBall);
playerBallList.get(playerIndex).add(shotIndex, cBall);
}
}
}
}
in geos.createcannonball
public Geometry createcannonball(Quaternion rotation, Vector3f translation)
{
Sphere c = new Sphere(Util.CANNONBALL_RESOLUTION,Util.CANNONBALL_RESOLUTION,Util.CANNONBALL_RADIUS);
Geometry cBall = new Geometry("cannonball", c);
Material cannonballMat = new Material (assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
cannonballMat.setColor("Color", ColorRGBA.Gray);
cBall.setMaterial(cannonballMat);
cBall.setLocalRotation(rotation);
cBall.setLocalTranslation(translation);
return cBall;
}
I’ve tried using zero vector and quaternion for translation and rotation. Still same.
All the code can be found on GitHub
The code regarding all this is in ClientMain.java (and creaing balls in CreateGeos). The server aspect doesn’t matter.
(Don’t mind how weird the GitHub is set up. I set this before I knew how to use git)
Thankful for replies!