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",
"type" : "FIXED_DOUBLE"
},
{
"name" : "rotationW",
"type" : "FIXED_FLOAT"
},
{
"name" : "rotationX",
"type" : "FIXED_DOUBLE"
@ -49,6 +45,10 @@
"name" : "rotationZ",
"type" : "FIXED_DOUBLE"
},
{
"name" : "rotationW",
"type" : "FIXED_DOUBLE"
},
{
"name" : "velocity",
"type" : "FIXED_DOUBLE"
@ -149,6 +149,7 @@
"rotationX",
"rotationY",
"rotationZ",
"rotationW",
"velocity",
"treeState"
]

View File

@ -144,9 +144,9 @@ public class AirplaneMovementTree implements BehaviorTree {
//update rotation
updateRotation(rotation,facingVector);
//add movement impulse
addMovementForce(velocity,facingVector,collidable);
addMovementForce(velocity,rotation,collidable);
//if server, update all clients to simulation changes
serverUpdateTree(position,facingVector,velocity);
serverUpdateTree(position,rotation,velocity);
} break;
case DECELERATING: {
//velocity calculation
@ -158,9 +158,9 @@ public class AirplaneMovementTree implements BehaviorTree {
//update rotation
updateRotation(rotation,facingVector);
//add movement impulse
addMovementForce(velocity,facingVector,collidable);
addMovementForce(velocity,rotation,collidable);
//if server, update all clients to simulation changes
serverUpdateTree(position,facingVector,velocity);
serverUpdateTree(position,rotation,velocity);
} break;
}
}
@ -185,8 +185,9 @@ public class AirplaneMovementTree implements BehaviorTree {
* @param facingVector The current facing vector
* @param collidable The collidable of the entity
*/
void addMovementForce(float velocity, Vector3d facingVector, Collidable collidable){
collidable.addImpulse(new Impulse(new Vector3d(facingVector), new Vector3d(0,0,0), new Vector3d(0,0,0), velocity * Main.deltaFrames, "movement"));
void addMovementForce(float velocity, Quaternionf rotation, Collidable collidable){
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 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){
int stateNumber = 0;
switch(this.state){
@ -213,9 +214,10 @@ public class AirplaneMovementTree implements BehaviorTree {
position.x,
position.y,
position.z,
facingVector.x,
facingVector.y,
facingVector.z,
rotation.x,
rotation.y,
rotation.z,
rotation.w,
velocity,
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(!Globals.RUN_SERVER){
Vector3d position = EntityUtils.getPosition(parent);
Quaternionf rotation = EntityUtils.getRotation(parent);
Vector3d facingVector = CreatureUtils.getFacingVector(parent);
float velocity = CreatureUtils.getVelocity(parent);
Globals.clientConnection.queueOutgoingMessage(
@ -109,9 +110,10 @@ public class GroundMovementTree implements BehaviorTree {
position.x,
position.y,
position.z,
facingVector.x,
facingVector.y,
facingVector.z,
rotation.x,
rotation.y,
rotation.z,
rotation.w,
velocity,
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(!Globals.RUN_SERVER){
Vector3d position = EntityUtils.getPosition(parent);
Quaternionf rotation = EntityUtils.getRotation(parent);
Vector3d facingVector = CreatureUtils.getFacingVector(parent);
float velocity = CreatureUtils.getVelocity(parent);
Globals.clientConnection.queueOutgoingMessage(
@ -139,9 +142,10 @@ public class GroundMovementTree implements BehaviorTree {
position.x,
position.y,
position.z,
facingVector.x,
facingVector.y,
facingVector.z,
rotation.x,
rotation.y,
rotation.z,
rotation.w,
velocity,
2 //magic number corresponding to state slowdown
)
@ -294,9 +298,10 @@ public class GroundMovementTree implements BehaviorTree {
position.x,
position.y,
position.z,
movementVector.x,
movementVector.y,
movementVector.z,
rotation.x,
rotation.y,
rotation.z,
rotation.w,
velocity,
0
),
@ -345,9 +350,10 @@ public class GroundMovementTree implements BehaviorTree {
position.x,
position.y,
position.z,
movementVector.x,
movementVector.y,
movementVector.z,
rotation.x,
rotation.y,
rotation.z,
rotation.w,
velocity,
1
),
@ -404,9 +410,10 @@ public class GroundMovementTree implements BehaviorTree {
position.x,
position.y,
position.z,
movementVector.x,
movementVector.y,
movementVector.z,
rotation.x,
rotation.y,
rotation.z,
rotation.w,
velocity,
2
),

View File

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