add gravity to movement tree

This commit is contained in:
austin 2021-06-28 01:59:58 -04:00
parent 3d0acb530e
commit 3f899ed746
2 changed files with 15 additions and 3 deletions

View File

@ -140,7 +140,7 @@ public class MovementTree {
state = MovementTreeState.MOVE; state = MovementTreeState.MOVE;
} }
//move the entity //move the entity
newPosition = new Vector3f(position).add(new Vector3f(movementVector).mul(velocity)); newPosition = new Vector3f(position).add(new Vector3f(movementVector).mul(velocity)).add(0,-9.8f,0);
//check/update if collision //check/update if collision
if(!Globals.collisionEngine.checkCanOccupyPosition(Globals.commonWorldData, parent, newPosition)){ if(!Globals.collisionEngine.checkCanOccupyPosition(Globals.commonWorldData, parent, newPosition)){
newPosition = Globals.collisionEngine.suggestMovementPosition(Globals.commonWorldData, parent, newPosition); newPosition = Globals.collisionEngine.suggestMovementPosition(Globals.commonWorldData, parent, newPosition);
@ -191,7 +191,7 @@ public class MovementTree {
} }
//check if can move forward (collision engine) //check if can move forward (collision engine)
//if can, move forward by entity movement stats //if can, move forward by entity movement stats
newPosition = new Vector3f(position).add(new Vector3f(movementVector).mul(velocity)); newPosition = new Vector3f(position).add(new Vector3f(movementVector).mul(velocity)).add(0,-9.8f,0);
if(!Globals.collisionEngine.checkCanOccupyPosition(Globals.commonWorldData, parent, newPosition)){ if(!Globals.collisionEngine.checkCanOccupyPosition(Globals.commonWorldData, parent, newPosition)){
newPosition = Globals.collisionEngine.suggestMovementPosition(Globals.commonWorldData, parent, newPosition); newPosition = Globals.collisionEngine.suggestMovementPosition(Globals.commonWorldData, parent, newPosition);
} }
@ -245,7 +245,7 @@ public class MovementTree {
state = MovementTreeState.IDLE; state = MovementTreeState.IDLE;
} }
//move the entity //move the entity
newPosition = new Vector3f(position).add(new Vector3f(movementVector).mul(velocity)); newPosition = new Vector3f(position).add(new Vector3f(movementVector).mul(velocity)).add(0,-9.8f,0);
if(!Globals.collisionEngine.checkCanOccupyPosition(Globals.commonWorldData, parent, newPosition)){ if(!Globals.collisionEngine.checkCanOccupyPosition(Globals.commonWorldData, parent, newPosition)){
newPosition = Globals.collisionEngine.suggestMovementPosition(Globals.commonWorldData, parent, newPosition); newPosition = Globals.collisionEngine.suggestMovementPosition(Globals.commonWorldData, parent, newPosition);
} }
@ -290,6 +290,9 @@ public class MovementTree {
entityActor.incrementAnimationTime(0.01); entityActor.incrementAnimationTime(0.01);
} }
} }
if(Globals.collisionEngine.gravityCheck(Globals.commonWorldData, parent)){
EntityUtils.getEntityPosition(parent).set(Globals.collisionEngine.suggestMovementPosition(Globals.commonWorldData,parent,new Vector3f(position.x,position.y - 9.8f,position.z)));
}
break; break;
} }
} }

View File

@ -107,4 +107,13 @@ public class CollisionEngine {
} }
} }
/*
Check if the entity is being accelerated by gravity
*/
public boolean gravityCheck(CommonWorldData w, Entity e){
float worldHeight = w.getElevationAtPoint(EntityUtils.getEntityPosition(e));
float entityHeight = EntityUtils.getEntityPosition(e).y;
return entityHeight > worldHeight + 0.1f;
}
} }