server rotation fix
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
This commit is contained in:
parent
8dcff7efe0
commit
a676d8ddca
@ -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
|
||||||
|
|
||||||
|
|||||||
@ -101,6 +101,9 @@ public class ClientGroundMovementTree implements BehaviorTree {
|
|||||||
long lastUpdateTime = 0;
|
long lastUpdateTime = 0;
|
||||||
//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
|
||||||
@ -186,44 +189,44 @@ 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();
|
||||||
switch(facing){
|
|
||||||
case FORWARD:
|
//
|
||||||
movementVector.normalize();
|
//rotation update
|
||||||
break;
|
if(this.state != MovementTreeState.IDLE){
|
||||||
case LEFT:
|
this.movementVector.set(facingVector);
|
||||||
movementVector.rotateY((float)(90 * Math.PI / 180)).normalize();
|
switch(facing){
|
||||||
break;
|
case FORWARD:
|
||||||
case RIGHT:
|
movementVector.normalize();
|
||||||
movementVector.rotateY((float)(-90 * Math.PI / 180)).normalize();
|
break;
|
||||||
break;
|
case LEFT:
|
||||||
case BACKWARD:
|
movementVector.rotateY((float)(90 * Math.PI / 180)).normalize();
|
||||||
movementVector.x = -movementVector.x;
|
break;
|
||||||
movementVector.z = -movementVector.z;
|
case RIGHT:
|
||||||
movementVector.normalize();
|
movementVector.rotateY((float)(-90 * Math.PI / 180)).normalize();
|
||||||
break;
|
break;
|
||||||
case FORWARD_LEFT:
|
case BACKWARD:
|
||||||
movementVector.rotateY((float)(45 * Math.PI / 180)).normalize();
|
movementVector.x = -movementVector.x;
|
||||||
break;
|
movementVector.z = -movementVector.z;
|
||||||
case FORWARD_RIGHT:
|
movementVector.normalize();
|
||||||
movementVector.rotateY((float)(-45 * Math.PI / 180)).normalize();
|
break;
|
||||||
break;
|
case FORWARD_LEFT:
|
||||||
case BACKWARD_LEFT:
|
movementVector.rotateY((float)(45 * Math.PI / 180)).normalize();
|
||||||
movementVector.rotateY((float)(135 * Math.PI / 180)).normalize();
|
break;
|
||||||
break;
|
case FORWARD_RIGHT:
|
||||||
case BACKWARD_RIGHT:
|
movementVector.rotateY((float)(-45 * Math.PI / 180)).normalize();
|
||||||
movementVector.rotateY((float)(-135 * Math.PI / 180)).normalize();
|
break;
|
||||||
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(movementVector.x,0,movementVector.z)).normalize();
|
||||||
Quaterniond movementQuaternion = new Quaterniond().rotationTo(MathUtils.getOriginVector(), new Vector3d(facingVector.x,0,facingVector.z)).normalize();
|
|
||||||
Quaterniond rotation = EntityUtils.getRotation(parent);
|
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);
|
rotation.set(movementQuaternion);
|
||||||
|
|
||||||
//parse attached network messages
|
//parse attached network messages
|
||||||
|
|||||||
@ -69,6 +69,9 @@ public class ServerGroundMovementTree implements BehaviorTree {
|
|||||||
CopyOnWriteArrayList<EntityMessage> networkMessageQueue = new CopyOnWriteArrayList<EntityMessage>();
|
CopyOnWriteArrayList<EntityMessage> networkMessageQueue = new CopyOnWriteArrayList<EntityMessage>();
|
||||||
|
|
||||||
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){
|
||||||
@ -161,45 +164,49 @@ 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();
|
||||||
switch(facing){
|
|
||||||
case FORWARD:
|
//
|
||||||
movementVector.normalize();
|
//rotation update
|
||||||
break;
|
if(this.state != MovementTreeState.IDLE){
|
||||||
case LEFT:
|
this.movementVector.set(facingVector);
|
||||||
movementVector.rotateY((float)(90 * Math.PI / 180)).normalize();
|
switch(facing){
|
||||||
break;
|
case FORWARD:
|
||||||
case RIGHT:
|
movementVector.normalize();
|
||||||
movementVector.rotateY((float)(-90 * Math.PI / 180)).normalize();
|
break;
|
||||||
break;
|
case LEFT:
|
||||||
case BACKWARD:
|
movementVector.rotateY((float)(90 * Math.PI / 180)).normalize();
|
||||||
movementVector.x = -movementVector.x;
|
break;
|
||||||
movementVector.z = -movementVector.z;
|
case RIGHT:
|
||||||
movementVector.normalize();
|
movementVector.rotateY((float)(-90 * Math.PI / 180)).normalize();
|
||||||
break;
|
break;
|
||||||
case FORWARD_LEFT:
|
case BACKWARD:
|
||||||
movementVector.rotateY((float)(45 * Math.PI / 180)).normalize();
|
movementVector.x = -movementVector.x;
|
||||||
break;
|
movementVector.z = -movementVector.z;
|
||||||
case FORWARD_RIGHT:
|
movementVector.normalize();
|
||||||
movementVector.rotateY((float)(-45 * Math.PI / 180)).normalize();
|
break;
|
||||||
break;
|
case FORWARD_LEFT:
|
||||||
case BACKWARD_LEFT:
|
movementVector.rotateY((float)(45 * Math.PI / 180)).normalize();
|
||||||
movementVector.rotateY((float)(135 * Math.PI / 180)).normalize();
|
break;
|
||||||
break;
|
case FORWARD_RIGHT:
|
||||||
case BACKWARD_RIGHT:
|
movementVector.rotateY((float)(-45 * Math.PI / 180)).normalize();
|
||||||
movementVector.rotateY((float)(-135 * Math.PI / 180)).normalize();
|
break;
|
||||||
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(movementVector.x,0,movementVector.z)).normalize();
|
||||||
Quaterniond movementQuaternion = new Quaterniond().rotationTo(MathUtils.getOriginVector(), new Vector3d(facingVector.x,0,facingVector.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);
|
||||||
|
|
||||||
|
|||||||
@ -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);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user