Hi, I am literally one step away from being done with my little game. I have one issue. This occurs when the player is holding down a WASD key while they press my pause button, P. Using the steps in the hello collision tutorial, I used onAction() with the keys to set booleans which are then toggled in the update loop. I moved this update loop to an AppState eventually, here’s the problem: When I setEnabled() to false, the update loop stops, I think, but when it is enabled again, the player appears in the location that they would have been if they had
never let go of the WASD key. After trying a lot of different routes, I have come to the conclusion I do not know enough about JME3 to solve the problem, or really understand it. I think it might be because setWalkDirection() is continuous? Not sure what that means or what to do about it. Any help on solving, identifying, or understanding the problem would be greatly appreciated. Here is the appstates
update loop:
[java]
public void update(float tpf)
{
/*
* Tests to make sure RunningAppState is enabled before updating the
* player's position.
*/
if (isEnabled())
{
camDir.set(app.getCamera().getDirection()).multLocal(0.6f);
camLeft.set(app.getCamera().getLeft().multLocal(.4f));
walkDirection.set(0,0,0);
if (app.getLeft())
{
/* Moves left */
walkDirection.addLocal(camLeft);
}
if (app.getRight())
{
/* Moves right */
walkDirection.addLocal(camLeft.negate());
}
if (app.getUp())
{
/* Moves forward */
walkDirection.addLocal(camDir);
}
if (app.getDown())
{
/* Moves backward */
walkDirection.addLocal(camDir.negate());
}
app.getPlayer().setWalkDirection(walkDirection);
/*
* This finds the player's location and sets the camera 5 units
* above it and 1 behind it.
*/
newcam = new Vector3f(app.getPlayer().getPhysicsLocation());
newcam.addLocal(camDir.negate().normalize().addLocal(0,5f, 0));
app.getCamera().setLocation(newcam);
}
[/java]