diff --git a/src/engine/objects/AbstractCharacter.java b/src/engine/objects/AbstractCharacter.java index 7834b0cb..f778755a 100644 --- a/src/engine/objects/AbstractCharacter.java +++ b/src/engine/objects/AbstractCharacter.java @@ -12,6 +12,7 @@ package engine.objects; import engine.Enum; import engine.Enum.*; import engine.InterestManagement.InterestManager; +import engine.InterestManagement.Terrain; import engine.InterestManagement.WorldGrid; import engine.exception.SerializationException; import engine.gameManager.*; @@ -985,11 +986,22 @@ public abstract class AbstractCharacter extends AbstractWorldObject { @Override public final void setLoc(final Vector3fImmutable value) { Regions region = Regions.GetRegionForTeleport(value); + float regionHeightOffset = 0; if(region != null){ this.region = region; - } - - super.setLoc(value); // set the location in the world + regionHeightOffset = region.lerpY(this); + this.inBuilding = region.level; // -1 not in building 0 on ground floor, 1 on first floor etc + this.inBuildingID = region.parentBuildingID; + this.inFloorID = region.room; + } else { + this.region = null; + this.inBuilding = -1; + this.inBuildingID = 0; + this.inFloorID = -1; + } + float terrainHeight = Terrain.getWorldHeight(value); + Vector3fImmutable finalLocation = new Vector3fImmutable(value.x,terrainHeight + regionHeightOffset, value.z); + super.setLoc(finalLocation); // set the location in the world this.resetLastSetLocUpdate(); }