better movement

pull/12/head
hYdos 2020-02-28 05:53:02 +10:00
parent 43ccd8f9ca
commit 7026669045
4 changed files with 33 additions and 24 deletions

View File

@ -41,7 +41,7 @@ public class Litecraft extends Game
public Litecraft()
{
INSTANCE = this;
Constants.movementSpeed = 0.00005f;
Constants.movementSpeed = 0.5f;
Constants.turnSpeed = 0.00006f;
Constants.gravity = new org.joml.Vector3f(0, -0.0000000005f, 0);
Constants.jumpPower = 0.00005f;

View File

@ -9,36 +9,39 @@ import com.github.hydos.ginger.main.settings.Constants;
public class Player extends RenderObject
{
private double currentSpeed = 0;
private float currentTurn = 0;
private float upwardsSpeed = 0;
private boolean isInAir = false;
private double upwardsSpeed;
public Player(TexturedModel model, Vector3f position, float rotX, float rotY, float rotZ, Vector3f scale)
{ super(model, position, rotX, rotY, rotZ, scale); }
private void checkInputs()
{
float ry = getRotY();
if (Window.isKeyDown(GLFW.GLFW_KEY_W))
{
this.currentSpeed = Constants.movementSpeed;
}
else if (Window.isKeyDown(GLFW.GLFW_KEY_S))
{
this.currentSpeed = -Constants.movementSpeed;
}
else
{
this.currentSpeed = 0;
position.z -= Math.cos(ry) * Constants.movementSpeed;
position.x += Math.sin(ry) * Constants.movementSpeed;
}
if (Window.isKeyDown(GLFW.GLFW_KEY_A))
{
this.currentTurn = (float) Constants.movementSpeed;
position.z -= Math.cos(ry) * Constants.movementSpeed;
position.x -= Math.sin(ry) * Constants.movementSpeed;
}
else if (Window.isKeyDown(GLFW.GLFW_KEY_D))
if (Window.isKeyDown(GLFW.GLFW_KEY_S))
{
this.currentTurn = (float) -Constants.movementSpeed;
position.z += Math.cos(ry) * Constants.movementSpeed;
position.x -= Math.sin(ry) * Constants.movementSpeed;
}
if (Window.isKeyDown(GLFW.GLFW_KEY_D))
{
position.z += Math.cos(ry) * Constants.movementSpeed;
position.x += Math.sin(ry) * Constants.movementSpeed;
}
if (Window.isKeyDown(GLFW.GLFW_KEY_SPACE))
{
jump();
@ -57,14 +60,8 @@ public class Player extends RenderObject
public void updateMovement()
{
checkInputs();
// super.increaseRotation(0, (float) ((currentTurn) * Window.getTime()), 0);
float distance = (float) ((currentSpeed) * (Window.getTime()));
float dx = (float) (distance * Math.sin(Math.toRadians(super.getRotY())));
float dz = (float) (distance * Math.cos(Math.toRadians(super.getRotY())));
super.increasePosition(dx, 0, dz);
super.increasePosition(0, (float) (upwardsSpeed * (Window.getTime())), 0);
upwardsSpeed += Constants.gravity.y() * Window.getTime();
isInAir = false;
upwardsSpeed = 0;
super.getPosition().y = 0;

View File

@ -6,7 +6,7 @@ import com.github.hydos.ginger.engine.render.models.TexturedModel;
public class RenderObject
{
private TexturedModel model;
private Vector3f position;
public Vector3f position;
private float rotX = 0, rotY = 0, rotZ = 0;
private Vector3f scale;
public boolean isVisible = true;
@ -20,6 +20,18 @@ public class RenderObject
this.rotZ = rotZ;
this.scale = scale;
}
public void x(float x) {
this.position.x = x;
}
public void y(float y) {
this.position.y = y;
}
public void z(float z) {
this.position.z = z;
}
public TexturedModel getModel()
{ return model; }

View File

@ -8,7 +8,7 @@ public class Constants
public static Vector3f gravity = new Vector3f(0,0,0);
public static float jumpPower = 0;
public static float turnSpeed = 0;
public static double movementSpeed = 0;
public static double movementSpeed = 1;
//terrain variables
public static float terrainSize = 100;
public static float terrainMaxHeight = 10;