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 - Scaling LODed chunks by lod level
Fix items falling below the ground Fix items falling below the ground
Fix server always rotating entity to face client camera -- should only be changing movement vector
# TODO # TODO

View File

@ -102,6 +102,9 @@ public class ClientGroundMovementTree implements BehaviorTree {
//the last position reported by the server //the last position reported by the server
Vector3d lastServerPosition = null; Vector3d lastServerPosition = null;
//the vector controling the direction the entity will move in
Vector3d movementVector = new Vector3d(1,0,0);
/** /**
* Constructor * Constructor
* @param e The parent entity * @param e The parent entity
@ -186,9 +189,13 @@ public class ClientGroundMovementTree implements BehaviorTree {
// Model entityModel = Globals.assetManager.fetchModel(EntityUtils.getEntityModelPath(parent)); // Model entityModel = Globals.assetManager.fetchModel(EntityUtils.getEntityModelPath(parent));
Vector3d position = EntityUtils.getPosition(parent); Vector3d position = EntityUtils.getPosition(parent);
Vector3d facingVector = CreatureUtils.getFacingVector(parent); Vector3d facingVector = CreatureUtils.getFacingVector(parent);
Vector3d movementVector = new Vector3d(facingVector);
DBody body = PhysicsEntityUtils.getDBody(parent); DBody body = PhysicsEntityUtils.getDBody(parent);
DVector3C linearVelocity = body.getLinearVel(); DVector3C linearVelocity = body.getLinearVel();
//
//rotation update
if(this.state != MovementTreeState.IDLE){
this.movementVector.set(facingVector);
switch(facing){ switch(facing){
case FORWARD: case FORWARD:
movementVector.normalize(); movementVector.normalize();
@ -217,13 +224,9 @@ public class ClientGroundMovementTree implements BehaviorTree {
movementVector.rotateY((float)(-135 * Math.PI / 180)).normalize(); movementVector.rotateY((float)(-135 * Math.PI / 180)).normalize();
break; break;
} }
// float movementYaw = CameraEntityUtils.getCameraYaw(Globals.playerCamera);
Quaterniond movementQuaternion = new Quaterniond().rotationTo(MathUtils.getOriginVector(), new Vector3d(facingVector.x,0,facingVector.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");
} }
Quaterniond movementQuaternion = new Quaterniond().rotationTo(MathUtils.getOriginVector(), new Vector3d(movementVector.x,0,movementVector.z)).normalize();
Quaterniond rotation = EntityUtils.getRotation(parent);
rotation.set(movementQuaternion); rotation.set(movementQuaternion);
//parse attached network messages //parse attached network messages

View File

@ -70,6 +70,9 @@ public class ServerGroundMovementTree implements BehaviorTree {
long lastUpdateTime = 0; long lastUpdateTime = 0;
//the vector organizing the direction the entity will move in
Vector3d movementVector = new Vector3d(1,0,0);
private ServerGroundMovementTree(Entity e){ private ServerGroundMovementTree(Entity e){
state = MovementTreeState.IDLE; state = MovementTreeState.IDLE;
@ -161,9 +164,13 @@ public class ServerGroundMovementTree implements BehaviorTree {
// Model entityModel = Globals.assetManager.fetchModel(EntityUtils.getEntityModelPath(parent)); // Model entityModel = Globals.assetManager.fetchModel(EntityUtils.getEntityModelPath(parent));
Vector3d position = EntityUtils.getPosition(parent); Vector3d position = EntityUtils.getPosition(parent);
Vector3d facingVector = CreatureUtils.getFacingVector(parent); Vector3d facingVector = CreatureUtils.getFacingVector(parent);
Vector3d movementVector = new Vector3d(facingVector);
DBody body = PhysicsEntityUtils.getDBody(parent); DBody body = PhysicsEntityUtils.getDBody(parent);
DVector3C linearVelocity = body.getLinearVel(); DVector3C linearVelocity = body.getLinearVel();
//
//rotation update
if(this.state != MovementTreeState.IDLE){
this.movementVector.set(facingVector);
switch(facing){ switch(facing){
case FORWARD: case FORWARD:
movementVector.normalize(); movementVector.normalize();
@ -192,14 +199,14 @@ public class ServerGroundMovementTree implements BehaviorTree {
movementVector.rotateY((float)(-135 * Math.PI / 180)).normalize(); movementVector.rotateY((float)(-135 * Math.PI / 180)).normalize();
break; 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); 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) //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){ if(facingVector.length() == 0){
throw new IllegalStateException("Facing vector length is 0. This will break ODE4J"); throw new IllegalStateException("Facing vector length is 0. This will break ODE4J");
} }
rotation.set(movementQuaternion);
//parse attached network messages //parse attached network messages
for(EntityMessage message : networkMessageQueue){ for(EntityMessage message : networkMessageQueue){
@ -269,7 +276,6 @@ public class ServerGroundMovementTree implements BehaviorTree {
); );
body.setAngularVel(0, 0, 0); body.setAngularVel(0, 0, 0);
// position.set(newPosition); // position.set(newPosition);
rotation.set(movementQuaternion);
GravityUtils.serverAttemptActivateGravity(parent); GravityUtils.serverAttemptActivateGravity(parent);
@ -320,7 +326,6 @@ public class ServerGroundMovementTree implements BehaviorTree {
); );
body.setAngularVel(0, 0, 0); body.setAngularVel(0, 0, 0);
// position.set(newPosition); // position.set(newPosition);
rotation.set(movementQuaternion);
GravityUtils.serverAttemptActivateGravity(parent); GravityUtils.serverAttemptActivateGravity(parent);
@ -380,7 +385,6 @@ public class ServerGroundMovementTree implements BehaviorTree {
); );
body.setAngularVel(0, 0, 0); body.setAngularVel(0, 0, 0);
// position.set(newPosition); // position.set(newPosition);
rotation.set(movementQuaternion);
GravityUtils.serverAttemptActivateGravity(parent); GravityUtils.serverAttemptActivateGravity(parent);

View File

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