Untangled some of the mess with movement controls in LayerWorld

Now entity getVelocity() method matches actual velocity for player
entities.

WTF was I thinking when I wrote that code? Past me very stupid.
This commit is contained in:
OLEGSHA 2020-11-08 12:46:12 +03:00
parent 1c5c91a712
commit 1daec9a4df
2 changed files with 18 additions and 7 deletions

View File

@ -84,26 +84,31 @@ public class LayerWorld extends Layer {
private void tmp_handleControls() { private void tmp_handleControls() {
EntityData player = client.getLocalPlayer(); EntityData player = client.getLocalPlayer();
angMat.set().rotateZ(player.getYaw()); angMat.identity().rotateZ(player.getYaw());
Vec3 movement = Vectors.grab3(); Vec3 movement = Vectors.grab3();
// Horizontal and vertical max control speed
final float movementSpeed = 0.1f * 60.0f;
// (0; 1], 1 is instant change, 0 is no control authority
final float controlAuthority = 0.1f;
movement.set(movementForward, -movementRight, 0); movement.set(movementForward, -movementRight, 0);
if (movementForward != 0 && movementRight != 0) movement.normalize(); if (movementForward != 0 && movementRight != 0) movement.normalize();
angMat.mul_(movement); // bug in jglm angMat.mul_(movement); // bug in jglm, .mul() and mul_() are swapped
movement.z = movementUp; movement.z = movementUp;
movement.mul(0.1f); movement.mul(movementSpeed);
movement.sub(velocity); movement.sub(velocity);
movement.mul(0.1f); movement.mul(controlAuthority);
velocity.add(movement); velocity.add(movement);
Vectors.release(movement); Vectors.release(movement);
Vec3 velCopy = Vectors.grab3().set(velocity); Vec3 velCopy = Vectors.grab3().set(velocity);
velCopy.mul((float) (GraphicsInterface.getFrameLength() * 60)); velCopy.mul((float) GraphicsInterface.getFrameLength());
player.getPosition().add(velCopy); player.move(velCopy);
player.getVelocity().set(velocity); player.getVelocity().set(velocity);
Vectors.release(velCopy); Vectors.release(velCopy);
@ -115,10 +120,16 @@ public class LayerWorld extends Layer {
this.client.getWorld().render(helper); this.client.getWorld().render(helper);
tmp_doEveryFrame();
FaceCulling.pop(); FaceCulling.pop();
helper.reset(); helper.reset();
} }
private void tmp_doEveryFrame() {
// Stub for the future
}
@Override @Override
protected void handleInput(Input input) { protected void handleInput(Input input) {
if (input.isConsumed()) return; if (input.isConsumed()) return;

View File

@ -116,7 +116,7 @@ public class QuadripedModel extends EntityRenderable {
*/ */
private float velocityCutoff = 10; private float velocityCutoff = 10;
private float walkingFrequency = 0.15f; private float walkingFrequency = 0.15f / 60.0f;
private float walkingSwing = (float) toRadians(30); private float walkingSwing = (float) toRadians(30);
private float bodyYaw = Float.NaN; private float bodyYaw = Float.NaN;