server rotation fix
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2024-06-22 16:51:14 -04:00
parent 8dcff7efe0
commit a676d8ddca
4 changed files with 78 additions and 68 deletions

View File

@ -384,6 +384,7 @@ Transvoxel implementation
- Scaling LODed chunks by lod level
Fix items falling below the ground
Fix server always rotating entity to face client camera -- should only be changing movement vector
# TODO

View File

@ -101,6 +101,9 @@ public class ClientGroundMovementTree implements BehaviorTree {
long lastUpdateTime = 0;
//the last position reported by the server
Vector3d lastServerPosition = null;
//the vector controling the direction the entity will move in
Vector3d movementVector = new Vector3d(1,0,0);
/**
* Constructor
@ -186,44 +189,44 @@ public class ClientGroundMovementTree implements BehaviorTree {
// Model entityModel = Globals.assetManager.fetchModel(EntityUtils.getEntityModelPath(parent));
Vector3d position = EntityUtils.getPosition(parent);
Vector3d facingVector = CreatureUtils.getFacingVector(parent);
Vector3d movementVector = new Vector3d(facingVector);
DBody body = PhysicsEntityUtils.getDBody(parent);
DVector3C linearVelocity = body.getLinearVel();
switch(facing){
case FORWARD:
movementVector.normalize();
break;
case LEFT:
movementVector.rotateY((float)(90 * Math.PI / 180)).normalize();
break;
case RIGHT:
movementVector.rotateY((float)(-90 * Math.PI / 180)).normalize();
break;
case BACKWARD:
movementVector.x = -movementVector.x;
movementVector.z = -movementVector.z;
movementVector.normalize();
break;
case FORWARD_LEFT:
movementVector.rotateY((float)(45 * Math.PI / 180)).normalize();
break;
case FORWARD_RIGHT:
movementVector.rotateY((float)(-45 * Math.PI / 180)).normalize();
break;
case BACKWARD_LEFT:
movementVector.rotateY((float)(135 * Math.PI / 180)).normalize();
break;
case BACKWARD_RIGHT:
movementVector.rotateY((float)(-135 * Math.PI / 180)).normalize();
break;
//
//rotation update
if(this.state != MovementTreeState.IDLE){
this.movementVector.set(facingVector);
switch(facing){
case FORWARD:
movementVector.normalize();
break;
case LEFT:
movementVector.rotateY((float)(90 * Math.PI / 180)).normalize();
break;
case RIGHT:
movementVector.rotateY((float)(-90 * Math.PI / 180)).normalize();
break;
case BACKWARD:
movementVector.x = -movementVector.x;
movementVector.z = -movementVector.z;
movementVector.normalize();
break;
case FORWARD_LEFT:
movementVector.rotateY((float)(45 * Math.PI / 180)).normalize();
break;
case FORWARD_RIGHT:
movementVector.rotateY((float)(-45 * Math.PI / 180)).normalize();
break;
case BACKWARD_LEFT:
movementVector.rotateY((float)(135 * Math.PI / 180)).normalize();
break;
case BACKWARD_RIGHT:
movementVector.rotateY((float)(-135 * Math.PI / 180)).normalize();
break;
}
}
// float movementYaw = CameraEntityUtils.getCameraYaw(Globals.playerCamera);
Quaterniond movementQuaternion = new Quaterniond().rotationTo(MathUtils.getOriginVector(), new Vector3d(facingVector.x,0,facingVector.z)).normalize();
Quaterniond movementQuaternion = new Quaterniond().rotationTo(MathUtils.getOriginVector(), new Vector3d(movementVector.x,0,movementVector.z)).normalize();
Quaterniond rotation = EntityUtils.getRotation(parent);
//TODO: optimize away and document (I know for the moment if this exception isn't here it will bite me in the ass later)
if(facingVector.length() == 0){
throw new IllegalStateException("Facing vector length is 0. This will break ODE4J");
}
rotation.set(movementQuaternion);
//parse attached network messages

View File

@ -69,6 +69,9 @@ public class ServerGroundMovementTree implements BehaviorTree {
CopyOnWriteArrayList<EntityMessage> networkMessageQueue = new CopyOnWriteArrayList<EntityMessage>();
long lastUpdateTime = 0;
//the vector organizing the direction the entity will move in
Vector3d movementVector = new Vector3d(1,0,0);
private ServerGroundMovementTree(Entity e){
@ -161,45 +164,49 @@ public class ServerGroundMovementTree implements BehaviorTree {
// Model entityModel = Globals.assetManager.fetchModel(EntityUtils.getEntityModelPath(parent));
Vector3d position = EntityUtils.getPosition(parent);
Vector3d facingVector = CreatureUtils.getFacingVector(parent);
Vector3d movementVector = new Vector3d(facingVector);
DBody body = PhysicsEntityUtils.getDBody(parent);
DVector3C linearVelocity = body.getLinearVel();
switch(facing){
case FORWARD:
movementVector.normalize();
break;
case LEFT:
movementVector.rotateY((float)(90 * Math.PI / 180)).normalize();
break;
case RIGHT:
movementVector.rotateY((float)(-90 * Math.PI / 180)).normalize();
break;
case BACKWARD:
movementVector.x = -movementVector.x;
movementVector.z = -movementVector.z;
movementVector.normalize();
break;
case FORWARD_LEFT:
movementVector.rotateY((float)(45 * Math.PI / 180)).normalize();
break;
case FORWARD_RIGHT:
movementVector.rotateY((float)(-45 * Math.PI / 180)).normalize();
break;
case BACKWARD_LEFT:
movementVector.rotateY((float)(135 * Math.PI / 180)).normalize();
break;
case BACKWARD_RIGHT:
movementVector.rotateY((float)(-135 * Math.PI / 180)).normalize();
break;
//
//rotation update
if(this.state != MovementTreeState.IDLE){
this.movementVector.set(facingVector);
switch(facing){
case FORWARD:
movementVector.normalize();
break;
case LEFT:
movementVector.rotateY((float)(90 * Math.PI / 180)).normalize();
break;
case RIGHT:
movementVector.rotateY((float)(-90 * Math.PI / 180)).normalize();
break;
case BACKWARD:
movementVector.x = -movementVector.x;
movementVector.z = -movementVector.z;
movementVector.normalize();
break;
case FORWARD_LEFT:
movementVector.rotateY((float)(45 * Math.PI / 180)).normalize();
break;
case FORWARD_RIGHT:
movementVector.rotateY((float)(-45 * Math.PI / 180)).normalize();
break;
case BACKWARD_LEFT:
movementVector.rotateY((float)(135 * Math.PI / 180)).normalize();
break;
case BACKWARD_RIGHT:
movementVector.rotateY((float)(-135 * Math.PI / 180)).normalize();
break;
}
}
// float movementYaw = CameraEntityUtils.getCameraYaw(Globals.playerCamera);
Quaterniond movementQuaternion = new Quaterniond().rotationTo(MathUtils.getOriginVector(), new Vector3d(facingVector.x,0,facingVector.z)).normalize();
Quaterniond movementQuaternion = new Quaterniond().rotationTo(MathUtils.getOriginVector(), new Vector3d(movementVector.x,0,movementVector.z)).normalize();
Quaterniond rotation = EntityUtils.getRotation(parent);
rotation.set(movementQuaternion);
//TODO: optimize away and document (I know for the moment if this exception isn't here it will bite me in the ass later)
if(facingVector.length() == 0){
throw new IllegalStateException("Facing vector length is 0. This will break ODE4J");
}
rotation.set(movementQuaternion);
//parse attached network messages
for(EntityMessage message : networkMessageQueue){
@ -269,7 +276,6 @@ public class ServerGroundMovementTree implements BehaviorTree {
);
body.setAngularVel(0, 0, 0);
// position.set(newPosition);
rotation.set(movementQuaternion);
GravityUtils.serverAttemptActivateGravity(parent);
@ -320,7 +326,6 @@ public class ServerGroundMovementTree implements BehaviorTree {
);
body.setAngularVel(0, 0, 0);
// position.set(newPosition);
rotation.set(movementQuaternion);
GravityUtils.serverAttemptActivateGravity(parent);
@ -380,7 +385,6 @@ public class ServerGroundMovementTree implements BehaviorTree {
);
body.setAngularVel(0, 0, 0);
// position.set(newPosition);
rotation.set(movementQuaternion);
GravityUtils.serverAttemptActivateGravity(parent);

View File

@ -182,11 +182,13 @@ public class ImGuiWindowMacros {
ImGui.text("Player Entity Details");
if(Globals.playerEntity != null){
ImGui.text("Position: " + EntityUtils.getPosition(Globals.playerEntity));
ImGui.text("Rotation: " + EntityUtils.getRotation(Globals.playerEntity));
//server pos
int serverIdForClientEntity = Globals.clientSceneWrapper.mapClientToServerId(Globals.playerEntity.getId());
Entity serverPlayerEntity = EntityLookupUtils.getEntityById(serverIdForClientEntity);
ImGui.text("Position (Server): " + EntityUtils.getPosition(serverPlayerEntity));
ImGui.text("Rotation (Server): " + EntityUtils.getRotation(serverPlayerEntity));
//client-side tree stuff
DBody body = PhysicsEntityUtils.getDBody(Globals.playerEntity);