add gravity to movement tree
This commit is contained in:
parent
3d0acb530e
commit
3f899ed746
@ -140,7 +140,7 @@ public class MovementTree {
|
||||
state = MovementTreeState.MOVE;
|
||||
}
|
||||
//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
|
||||
if(!Globals.collisionEngine.checkCanOccupyPosition(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)
|
||||
//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)){
|
||||
newPosition = Globals.collisionEngine.suggestMovementPosition(Globals.commonWorldData, parent, newPosition);
|
||||
}
|
||||
@ -245,7 +245,7 @@ public class MovementTree {
|
||||
state = MovementTreeState.IDLE;
|
||||
}
|
||||
//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)){
|
||||
newPosition = Globals.collisionEngine.suggestMovementPosition(Globals.commonWorldData, parent, newPosition);
|
||||
}
|
||||
@ -290,6 +290,9 @@ public class MovementTree {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user