forked from MagicBane/Server
Added functionality to handlePlayerCollision method in PlayerCharacter.java to actively prevent players from standing in each other.
This commit is contained in:
@@ -286,7 +286,6 @@ public class PlayerCharacter extends AbstractCharacter {
|
|||||||
public void updateBounds() {
|
public void updateBounds() {
|
||||||
this.playerBounds.setBounds(this);
|
this.playerBounds.setBounds(this);
|
||||||
this.checkCollisionsWithOtherPlayers();
|
this.checkCollisionsWithOtherPlayers();
|
||||||
// This is a test to see if it will push to the docker container
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkCollisionsWithOtherPlayers() {
|
public void checkCollisionsWithOtherPlayers() {
|
||||||
@@ -295,6 +294,8 @@ public class PlayerCharacter extends AbstractCharacter {
|
|||||||
if (obj instanceof PlayerCharacter && obj != this) {
|
if (obj instanceof PlayerCharacter && obj != this) {
|
||||||
PlayerCharacter otherPlayer = (PlayerCharacter) obj;
|
PlayerCharacter otherPlayer = (PlayerCharacter) obj;
|
||||||
if (Bounds.collide(this.getBounds(), otherPlayer.getBounds(), 0.1f)) {
|
if (Bounds.collide(this.getBounds(), otherPlayer.getBounds(), 0.1f)) {
|
||||||
|
System.out.println("Collision detected with player: " + otherPlayer.getFirstName());
|
||||||
|
ChatManager.chatSystemInfo(otherPlayer, "Has Collided with YOU");
|
||||||
// Handle collision with other player
|
// Handle collision with other player
|
||||||
handleCollisionWithPlayer(otherPlayer);
|
handleCollisionWithPlayer(otherPlayer);
|
||||||
}
|
}
|
||||||
@@ -303,9 +304,28 @@ public class PlayerCharacter extends AbstractCharacter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleCollisionWithPlayer(PlayerCharacter otherPlayer) {
|
private void handleCollisionWithPlayer(PlayerCharacter otherPlayer) {
|
||||||
// Implement collision response here
|
Vector3fImmutable myPos = this.getLoc();
|
||||||
System.out.println("Collision detected with player: " + otherPlayer.getFirstName());
|
Vector3fImmutable otherPlayerPos = otherPlayer.getLoc();
|
||||||
ChatManager.chatSystemInfo(otherPlayer, "Has Collided with YOU");
|
|
||||||
|
// Calculate direction vector
|
||||||
|
Vector3fImmutable direction = myPos.subtract(otherPlayerPos).normalize();
|
||||||
|
|
||||||
|
// Move players apart
|
||||||
|
float separationDistance = 1.0f; // Adjust this value as needed
|
||||||
|
Vector3fImmutable myNewPos = myPos.add(direction.mult(separationDistance / 2));
|
||||||
|
Vector3fImmutable otherPlayerNewPos = otherPlayerPos.subtract(direction.mult(separationDistance / 2.0f));
|
||||||
|
|
||||||
|
// Update positions
|
||||||
|
this.setLoc(myNewPos);
|
||||||
|
otherPlayer.setLoc(otherPlayerNewPos);
|
||||||
|
|
||||||
|
// Refresh both players in the world
|
||||||
|
WorldGrid.updateObject(this);
|
||||||
|
WorldGrid.updateObject(otherPlayer);
|
||||||
|
|
||||||
|
// Refresh both players in the world
|
||||||
|
WorldGrid.updateObject(this);
|
||||||
|
WorldGrid.updateObject(otherPlayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Building getUpdatedBindBuilding(PlayerCharacter player) {
|
public static Building getUpdatedBindBuilding(PlayerCharacter player) {
|
||||||
|
|||||||
Reference in New Issue
Block a user