Fix airplane movement

This commit is contained in:
austin 2022-12-30 14:18:23 -05:00
parent 6b29863016
commit 9d9adea61f
5 changed files with 59 additions and 43 deletions

View File

@ -33,10 +33,6 @@
"name" : "positionZ", "name" : "positionZ",
"type" : "FIXED_DOUBLE" "type" : "FIXED_DOUBLE"
}, },
{
"name" : "rotationW",
"type" : "FIXED_FLOAT"
},
{ {
"name" : "rotationX", "name" : "rotationX",
"type" : "FIXED_DOUBLE" "type" : "FIXED_DOUBLE"
@ -49,6 +45,10 @@
"name" : "rotationZ", "name" : "rotationZ",
"type" : "FIXED_DOUBLE" "type" : "FIXED_DOUBLE"
}, },
{
"name" : "rotationW",
"type" : "FIXED_DOUBLE"
},
{ {
"name" : "velocity", "name" : "velocity",
"type" : "FIXED_DOUBLE" "type" : "FIXED_DOUBLE"
@ -149,6 +149,7 @@
"rotationX", "rotationX",
"rotationY", "rotationY",
"rotationZ", "rotationZ",
"rotationW",
"velocity", "velocity",
"treeState" "treeState"
] ]

View File

@ -144,9 +144,9 @@ public class AirplaneMovementTree implements BehaviorTree {
//update rotation //update rotation
updateRotation(rotation,facingVector); updateRotation(rotation,facingVector);
//add movement impulse //add movement impulse
addMovementForce(velocity,facingVector,collidable); addMovementForce(velocity,rotation,collidable);
//if server, update all clients to simulation changes //if server, update all clients to simulation changes
serverUpdateTree(position,facingVector,velocity); serverUpdateTree(position,rotation,velocity);
} break; } break;
case DECELERATING: { case DECELERATING: {
//velocity calculation //velocity calculation
@ -158,9 +158,9 @@ public class AirplaneMovementTree implements BehaviorTree {
//update rotation //update rotation
updateRotation(rotation,facingVector); updateRotation(rotation,facingVector);
//add movement impulse //add movement impulse
addMovementForce(velocity,facingVector,collidable); addMovementForce(velocity,rotation,collidable);
//if server, update all clients to simulation changes //if server, update all clients to simulation changes
serverUpdateTree(position,facingVector,velocity); serverUpdateTree(position,rotation,velocity);
} break; } break;
} }
} }
@ -185,8 +185,9 @@ public class AirplaneMovementTree implements BehaviorTree {
* @param facingVector The current facing vector * @param facingVector The current facing vector
* @param collidable The collidable of the entity * @param collidable The collidable of the entity
*/ */
void addMovementForce(float velocity, Vector3d facingVector, Collidable collidable){ void addMovementForce(float velocity, Quaternionf rotation, Collidable collidable){
collidable.addImpulse(new Impulse(new Vector3d(facingVector), new Vector3d(0,0,0), new Vector3d(0,0,0), velocity * Main.deltaFrames, "movement")); Vector3f impulseDir = rotation.transform(new Vector3f(0,0,1));
collidable.addImpulse(new Impulse(new Vector3d(impulseDir.x,impulseDir.y,impulseDir.z), new Vector3d(0,0,0), new Vector3d(0,0,0), velocity * Main.deltaFrames, "movement"));
} }
/** /**
@ -195,7 +196,7 @@ public class AirplaneMovementTree implements BehaviorTree {
* @param facingVector The facing vector of the airplane * @param facingVector The facing vector of the airplane
* @param velocity The velocity of the airplane * @param velocity The velocity of the airplane
*/ */
void serverUpdateTree(Vector3d position, Vector3d facingVector, float velocity){ void serverUpdateTree(Vector3d position, Quaternionf rotation, float velocity){
if(Globals.RUN_SERVER){ if(Globals.RUN_SERVER){
int stateNumber = 0; int stateNumber = 0;
switch(this.state){ switch(this.state){
@ -213,9 +214,10 @@ public class AirplaneMovementTree implements BehaviorTree {
position.x, position.x,
position.y, position.y,
position.z, position.z,
facingVector.x, rotation.x,
facingVector.y, rotation.y,
facingVector.z, rotation.z,
rotation.w,
velocity, velocity,
stateNumber stateNumber
), ),

View File

@ -100,6 +100,7 @@ public class GroundMovementTree implements BehaviorTree {
//if we aren't the server, alert the server we intend to walk forward //if we aren't the server, alert the server we intend to walk forward
if(!Globals.RUN_SERVER){ if(!Globals.RUN_SERVER){
Vector3d position = EntityUtils.getPosition(parent); Vector3d position = EntityUtils.getPosition(parent);
Quaternionf rotation = EntityUtils.getRotation(parent);
Vector3d facingVector = CreatureUtils.getFacingVector(parent); Vector3d facingVector = CreatureUtils.getFacingVector(parent);
float velocity = CreatureUtils.getVelocity(parent); float velocity = CreatureUtils.getVelocity(parent);
Globals.clientConnection.queueOutgoingMessage( Globals.clientConnection.queueOutgoingMessage(
@ -109,9 +110,10 @@ public class GroundMovementTree implements BehaviorTree {
position.x, position.x,
position.y, position.y,
position.z, position.z,
facingVector.x, rotation.x,
facingVector.y, rotation.y,
facingVector.z, rotation.z,
rotation.w,
velocity, velocity,
0 //magic number corresponding to state startup 0 //magic number corresponding to state startup
) )
@ -130,6 +132,7 @@ public class GroundMovementTree implements BehaviorTree {
//if we aren't the server, alert the server we intend to slow down //if we aren't the server, alert the server we intend to slow down
if(!Globals.RUN_SERVER){ if(!Globals.RUN_SERVER){
Vector3d position = EntityUtils.getPosition(parent); Vector3d position = EntityUtils.getPosition(parent);
Quaternionf rotation = EntityUtils.getRotation(parent);
Vector3d facingVector = CreatureUtils.getFacingVector(parent); Vector3d facingVector = CreatureUtils.getFacingVector(parent);
float velocity = CreatureUtils.getVelocity(parent); float velocity = CreatureUtils.getVelocity(parent);
Globals.clientConnection.queueOutgoingMessage( Globals.clientConnection.queueOutgoingMessage(
@ -139,9 +142,10 @@ public class GroundMovementTree implements BehaviorTree {
position.x, position.x,
position.y, position.y,
position.z, position.z,
facingVector.x, rotation.x,
facingVector.y, rotation.y,
facingVector.z, rotation.z,
rotation.w,
velocity, velocity,
2 //magic number corresponding to state slowdown 2 //magic number corresponding to state slowdown
) )
@ -294,9 +298,10 @@ public class GroundMovementTree implements BehaviorTree {
position.x, position.x,
position.y, position.y,
position.z, position.z,
movementVector.x, rotation.x,
movementVector.y, rotation.y,
movementVector.z, rotation.z,
rotation.w,
velocity, velocity,
0 0
), ),
@ -345,9 +350,10 @@ public class GroundMovementTree implements BehaviorTree {
position.x, position.x,
position.y, position.y,
position.z, position.z,
movementVector.x, rotation.x,
movementVector.y, rotation.y,
movementVector.z, rotation.z,
rotation.w,
velocity, velocity,
1 1
), ),
@ -404,9 +410,10 @@ public class GroundMovementTree implements BehaviorTree {
position.x, position.x,
position.y, position.y,
position.z, position.z,
movementVector.x, rotation.x,
movementVector.y, rotation.y,
movementVector.z, rotation.z,
rotation.w,
velocity, velocity,
2 2
), ),

View File

@ -30,10 +30,10 @@ public class EntityMessage extends NetworkMessage {
double positionX; double positionX;
double positionY; double positionY;
double positionZ; double positionZ;
float rotationW;
double rotationX; double rotationX;
double rotationY; double rotationY;
double rotationZ; double rotationZ;
double rotationW;
double velocity; double velocity;
int treeState; int treeState;
int propertyType; int propertyType;
@ -109,14 +109,6 @@ public class EntityMessage extends NetworkMessage {
this.positionZ = positionZ; this.positionZ = positionZ;
} }
public float getrotationW() {
return rotationW;
}
public void setrotationW(float rotationW) {
this.rotationW = rotationW;
}
public double getrotationX() { public double getrotationX() {
return rotationX; return rotationX;
} }
@ -141,6 +133,14 @@ public class EntityMessage extends NetworkMessage {
this.rotationZ = rotationZ; this.rotationZ = rotationZ;
} }
public double getrotationW() {
return rotationW;
}
public void setrotationW(double rotationW) {
this.rotationW = rotationW;
}
public double getvelocity() { public double getvelocity() {
return velocity; return velocity;
} }
@ -505,12 +505,13 @@ public class EntityMessage extends NetworkMessage {
rVal.setrotationX(ByteStreamUtils.popDoubleFromByteQueue(byteStream)); rVal.setrotationX(ByteStreamUtils.popDoubleFromByteQueue(byteStream));
rVal.setrotationY(ByteStreamUtils.popDoubleFromByteQueue(byteStream)); rVal.setrotationY(ByteStreamUtils.popDoubleFromByteQueue(byteStream));
rVal.setrotationZ(ByteStreamUtils.popDoubleFromByteQueue(byteStream)); rVal.setrotationZ(ByteStreamUtils.popDoubleFromByteQueue(byteStream));
rVal.setrotationW(ByteStreamUtils.popDoubleFromByteQueue(byteStream));
rVal.setvelocity(ByteStreamUtils.popDoubleFromByteQueue(byteStream)); rVal.setvelocity(ByteStreamUtils.popDoubleFromByteQueue(byteStream));
rVal.settreeState(ByteStreamUtils.popIntFromByteQueue(byteStream)); rVal.settreeState(ByteStreamUtils.popIntFromByteQueue(byteStream));
return rVal; return rVal;
} }
public static EntityMessage constructmoveUpdateMessage(int entityID,long time,double positionX,double positionY,double positionZ,double rotationX,double rotationY,double rotationZ,double velocity,int treeState){ public static EntityMessage constructmoveUpdateMessage(int entityID,long time,double positionX,double positionY,double positionZ,double rotationX,double rotationY,double rotationZ,double rotationW,double velocity,int treeState){
EntityMessage rVal = new EntityMessage(EntityMessageType.MOVEUPDATE); EntityMessage rVal = new EntityMessage(EntityMessageType.MOVEUPDATE);
rVal.setentityID(entityID); rVal.setentityID(entityID);
rVal.settime(time); rVal.settime(time);
@ -520,6 +521,7 @@ public class EntityMessage extends NetworkMessage {
rVal.setrotationX(rotationX); rVal.setrotationX(rotationX);
rVal.setrotationY(rotationY); rVal.setrotationY(rotationY);
rVal.setrotationZ(rotationZ); rVal.setrotationZ(rotationZ);
rVal.setrotationW(rotationW);
rVal.setvelocity(velocity); rVal.setvelocity(velocity);
rVal.settreeState(treeState); rVal.settreeState(treeState);
rVal.serialize(); rVal.serialize();
@ -850,7 +852,7 @@ public class EntityMessage extends NetworkMessage {
} }
break; break;
case MOVEUPDATE: case MOVEUPDATE:
rawBytes = new byte[2+4+8+8+8+8+8+8+8+8+4]; rawBytes = new byte[2+4+8+8+8+8+8+8+8+8+8+4];
//message header //message header
rawBytes[0] = TypeBytes.MESSAGE_TYPE_ENTITY; rawBytes[0] = TypeBytes.MESSAGE_TYPE_ENTITY;
//entity messaage header //entity messaage header
@ -887,13 +889,17 @@ public class EntityMessage extends NetworkMessage {
for(int i = 0; i < 8; i++){ for(int i = 0; i < 8; i++){
rawBytes[54+i] = intValues[i]; rawBytes[54+i] = intValues[i];
} }
intValues = ByteStreamUtils.serializeDoubleToBytes(velocity); intValues = ByteStreamUtils.serializeDoubleToBytes(rotationW);
for(int i = 0; i < 8; i++){ for(int i = 0; i < 8; i++){
rawBytes[62+i] = intValues[i]; rawBytes[62+i] = intValues[i];
} }
intValues = ByteStreamUtils.serializeDoubleToBytes(velocity);
for(int i = 0; i < 8; i++){
rawBytes[70+i] = intValues[i];
}
intValues = ByteStreamUtils.serializeIntToBytes(treeState); intValues = ByteStreamUtils.serializeIntToBytes(treeState);
for(int i = 0; i < 4; i++){ for(int i = 0; i < 4; i++){
rawBytes[70+i] = intValues[i]; rawBytes[78+i] = intValues[i];
} }
break; break;
case ATTACKUPDATE: case ATTACKUPDATE:

View File

@ -34,7 +34,7 @@ Message categories
*/ */
public static final byte ENTITY_MESSAGE_TYPE_SETPOSITION_SIZE = 38; public static final byte ENTITY_MESSAGE_TYPE_SETPOSITION_SIZE = 38;
public static final byte ENTITY_MESSAGE_TYPE_SETFACING_SIZE = 38; public static final byte ENTITY_MESSAGE_TYPE_SETFACING_SIZE = 38;
public static final byte ENTITY_MESSAGE_TYPE_MOVEUPDATE_SIZE = 74; public static final byte ENTITY_MESSAGE_TYPE_MOVEUPDATE_SIZE = 82;
public static final byte ENTITY_MESSAGE_TYPE_ATTACKUPDATE_SIZE = 74; public static final byte ENTITY_MESSAGE_TYPE_ATTACKUPDATE_SIZE = 74;
public static final byte ENTITY_MESSAGE_TYPE_MOVE_SIZE = 38; public static final byte ENTITY_MESSAGE_TYPE_MOVE_SIZE = 38;
public static final byte ENTITY_MESSAGE_TYPE_KILL_SIZE = 14; public static final byte ENTITY_MESSAGE_TYPE_KILL_SIZE = 14;