Compare commits

..

No commits in common. 'playercollision-1' and 'master' have entirely different histories.

  1. 5
      .gitignore
  2. 10
      src/engine/gameManager/MovementManager.java
  3. 41
      src/engine/math/Bounds.java
  4. 8
      src/engine/objects/PlayerCharacter.java

5
.gitignore vendored

@ -24,8 +24,3 @@ @@ -24,8 +24,3 @@
hs_err_pid*
replay_pid*
*.idea/
Server.iml
*.gitignore
prestonbane.iml
qodana.yaml

10
src/engine/gameManager/MovementManager.java

@ -216,16 +216,6 @@ public enum MovementManager { @@ -216,16 +216,6 @@ public enum MovementManager {
}
if (toMove.getObjectType().equals(GameObjectType.PlayerCharacter)) {
Vector3fImmutable playerCollidePoint = Bounds.PlayerCollisionPoint((PlayerCharacter) toMove, toMove.getLoc(), endLocation);
if (playerCollidePoint != null) {
msg.setEndCoord(playerCollidePoint);
endLocation = playerCollidePoint;
collide = true;
}
}
if (toMove.getObjectType() == GameObjectType.PlayerCharacter && ((PlayerCharacter) toMove).isTeleportMode()) {
toMove.teleport(endLocation);
return;

41
src/engine/math/Bounds.java

@ -81,7 +81,7 @@ public class Bounds { @@ -81,7 +81,7 @@ public class Bounds {
Bounds identityBounds = Bounds.borrow();
identityBounds.setBounds(location);
collisionState = collide(targetBounds, identityBounds, 0.1f);
collisionState = collide(targetBounds, identityBounds, 0.0f);
identityBounds.release();
return collisionState;
}
@ -267,45 +267,6 @@ public class Bounds { @@ -267,45 +267,6 @@ public class Bounds {
return collidePoint;
}
public static Vector3fImmutable PlayerCollisionPoint(PlayerCharacter player, Vector3fImmutable start, Vector3fImmutable end) {
Vector3fImmutable collidePoint = null;
float distance = player.getLoc().distance2D(end);
// Check for building collisions first
collidePoint = PlayerBuildingCollisionPoint(player, start, end);
if (collidePoint != null) {
return collidePoint;
}
// Now check for player collisions
HashSet<AbstractWorldObject> nearbyPlayers = WorldGrid.getObjectsInRangePartial(player, distance + 2, MBServerStatics.MASK_PLAYER);
float minDistance = 5.0f; // Minimum distance between players
for (AbstractWorldObject awo : nearbyPlayers) {
PlayerCharacter otherPlayer = (PlayerCharacter) awo;
if (otherPlayer == player) continue;
Vector3fImmutable otherLoc = otherPlayer.getLoc();
Vector3fImmutable closestPoint = getClosestPointOnLine(start, end, otherLoc);
if (closestPoint.distance2D(otherLoc) < minDistance) {
// Collision detected, adjust end point
Vector3fImmutable pushVector = closestPoint.subtract(otherLoc).normalize();
collidePoint = closestPoint.add(pushVector.scaleAdd(minDistance, Vector3fImmutable.ZERO));
break;
}
}
return collidePoint != null ? collidePoint : end;
}
private static Vector3fImmutable getClosestPointOnLine(Vector3fImmutable lineStart, Vector3fImmutable lineEnd, Vector3fImmutable point) {
Vector3fImmutable line = lineEnd.subtract(lineStart);
float t = point.subtract(lineStart).dot(line) / line.dot(line);
t = Math.max(0, Math.min(1, t));
return lineStart.add(line.scaleAdd(t, Vector3fImmutable.ZERO));
}
public static boolean linesTouching(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) {
float denominator = ((x2 - x1) * (y4 - y3)) - ((y2 - y1) * (x4 - x3));
float numerator1 = ((y1 - y3) * (x4 - x3)) - ((x1 - x3) * (y4 - y3));

8
src/engine/objects/PlayerCharacter.java

@ -26,6 +26,7 @@ import engine.job.JobScheduler; @@ -26,6 +26,7 @@ import engine.job.JobScheduler;
import engine.jobs.DeferredPowerJob;
import engine.jobs.FinishSpireEffectJob;
import engine.jobs.NoTimeJob;
import engine.math.Bounds;
import engine.math.FastMath;
import engine.math.Vector3fImmutable;
import engine.net.ByteBufferWriter;
@ -268,6 +269,9 @@ public class PlayerCharacter extends AbstractCharacter { @@ -268,6 +269,9 @@ public class PlayerCharacter extends AbstractCharacter {
this.hash = rs.getString("hash");
// For debugging skills
// CharacterSkill.printSkills(this);
}
public static Building getUpdatedBindBuilding(PlayerCharacter player) {
@ -4561,6 +4565,9 @@ public class PlayerCharacter extends AbstractCharacter { @@ -4561,6 +4565,9 @@ public class PlayerCharacter extends AbstractCharacter {
this.charItemManager = new CharacterItemManager(this);
Bounds playerBounds = Bounds.borrow();
playerBounds.setBounds(this.getLoc());
this.setBounds(playerBounds);
}
@Override
@ -5356,7 +5363,6 @@ public class PlayerCharacter extends AbstractCharacter { @@ -5356,7 +5363,6 @@ public class PlayerCharacter extends AbstractCharacter {
moveToMsg.setSourceType(GameObjectType.PlayerCharacter.ordinal());
moveToMsg.setSourceID(this.getObjectUUID());
Dispatch dispatch = Dispatch.borrow(this, moveToMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY);

Loading…
Cancel
Save