Fix Moving NPC bugs see desc.

Fixed Straight Moving NPC from stopping if the player stands next to it.
Hopefully fixed the bug where if you time it right you could walk into the path of a moving NPC.
This commit is contained in:
JappaWakka 2024-09-26 19:44:32 +02:00
parent 4fca486fab
commit d02763959f
2 changed files with 113 additions and 96 deletions

View File

@ -657,6 +657,10 @@
''frontRotation = original faceRotation ''frontRotation = original faceRotation
Dim frontRotation As Integer = Me.faceRotation Dim frontRotation As Integer = Me.faceRotation
''for the check if the NPC can rotate when it can't walk
Dim CanRotate As Boolean = False
Dim OnlyRotateRotation = Me.faceRotation
Dim contains As Boolean = False Dim contains As Boolean = False
Dim newPosition As Vector3 = (GetMove(newRotation) / Speed) + Me.Position Dim newPosition As Vector3 = (GetMove(newRotation) / Speed) + Me.Position
Dim blocked As Boolean = False Dim blocked As Boolean = False
@ -677,15 +681,53 @@
End If End If
Next Next
End If End If
Else
For Each r As Rectangle In Me.MoveRectangles
If r.Contains(New Point(CInt(newPosition.X), CInt(newPosition.Z))) = True Then
CanRotate = True
OnlyRotateRotation = newRotation
Exit For
End If
Next
End If
If contains = True Then
'' Only change faceRotation when it's possible to move
Me.faceRotation = newRotation
Moved = 1.0F
Else
'' If not possible to move forward, check right
newRotation = frontRotation + 1
If newRotation > 3 Then
newRotation = newRotation - 4
End If
newPosition = (GetMove(newRotation) / Speed) + Me.Position
If CheckBlockedByPlayerOrNPC(newPosition) = False Then
If CheckCollision(newPosition) = True Then
For Each r As Rectangle In Me.MoveRectangles
If r.Contains(New Point(CInt(newPosition.X), CInt(newPosition.Z))) = True Then
contains = True
Exit For
End If
Next
End If
Else
For Each r As Rectangle In Me.MoveRectangles
If r.Contains(New Point(CInt(newPosition.X), CInt(newPosition.Z))) = True Then
CanRotate = True
OnlyRotateRotation = newRotation
Exit For
End If
Next
End If
If contains = True Then If contains = True Then
'' Only change faceRotation when it's possible to move '' Only change faceRotation when it's possible to move
Me.faceRotation = newRotation Me.faceRotation = newRotation
Moved = 1.0F Moved = 1.0F
Else Else
'' If not possible to move forward, check right '' If not possible to move to the right, check left
newRotation = frontRotation + 1 newRotation = frontRotation - 1
If newRotation > 3 Then If newRotation < 0 Then
newRotation = newRotation - 4 newRotation = newRotation + 4
End If End If
newPosition = (GetMove(newRotation) / Speed) + Me.Position newPosition = (GetMove(newRotation) / Speed) + Me.Position
If CheckBlockedByPlayerOrNPC(newPosition) = False Then If CheckBlockedByPlayerOrNPC(newPosition) = False Then
@ -697,87 +739,52 @@
End If End If
Next Next
End If End If
Else
For Each r As Rectangle In Me.MoveRectangles
If r.Contains(New Point(CInt(newPosition.X), CInt(newPosition.Z))) = True Then
CanRotate = True
OnlyRotateRotation = newRotation
Exit For
End If
Next
End If
If contains = True Then
'' Only change faceRotation when it's possible to move
Me.faceRotation = newRotation
Moved = 1.0F
Else
'' If not possible to move to the left, check behind
newRotation = frontRotation + 2
If newRotation > 3 Then
newRotation = newRotation - 4
End If
newPosition = (GetMove(newRotation) / Speed) + Me.Position
If CheckBlockedByPlayerOrNPC(newPosition) = False Then
If CheckCollision(newPosition) = True Then
For Each r As Rectangle In Me.MoveRectangles
If r.Contains(New Point(CInt(newPosition.X), CInt(newPosition.Z))) = True Then
contains = True
Exit For
End If
Next
End If
Else
For Each r As Rectangle In Me.MoveRectangles
If r.Contains(New Point(CInt(newPosition.X), CInt(newPosition.Z))) = True Then
CanRotate = True
OnlyRotateRotation = newRotation
Exit For
End If
Next
End If
If contains = True Then If contains = True Then
'' Only change faceRotation when it's possible to move '' Only change faceRotation when it's possible to move
Me.faceRotation = newRotation Me.faceRotation = newRotation
Moved = 1.0F Moved = 1.0F
Else Else
'' If not possible to move to the right, check left If CanRotate = True Then
newRotation = frontRotation - 1 Me.faceRotation = OnlyRotateRotation
If newRotation < 0 Then
newRotation = newRotation + 4
End If End If
newPosition = (GetMove(newRotation) / Speed) + Me.Position
If CheckBlockedByPlayerOrNPC(newPosition) = False Then
If CheckCollision(newPosition) = True Then
For Each r As Rectangle In Me.MoveRectangles
If r.Contains(New Point(CInt(newPosition.X), CInt(newPosition.Z))) = True Then
contains = True
Exit For
End If
Next
End If
If contains = True Then
'' Only change faceRotation when it's possible to move
Me.faceRotation = newRotation
Moved = 1.0F
Else
'' If not possible to move to the left, check behind
newRotation = frontRotation + 2
If newRotation > 3 Then
newRotation = newRotation - 4
End If
newPosition = (GetMove(newRotation) / Speed) + Me.Position
If CheckBlockedByPlayerOrNPC(newPosition) = False Then
If CheckCollision(newPosition) = True Then
For Each r As Rectangle In Me.MoveRectangles
If r.Contains(New Point(CInt(newPosition.X), CInt(newPosition.Z))) = True Then
contains = True
Exit For
End If
Next
End If
If contains = True Then
'' Only change faceRotation when it's possible to move
Me.faceRotation = newRotation
Moved = 1.0F
End If
Else
Dim CanRotate As Boolean = False
For Each r As Rectangle In Me.MoveRectangles
If r.Contains(New Point(CInt(newPosition.X), CInt(newPosition.Z))) = True Then
CanRotate = True
Exit For
End If
Next
If CanRotate = True Then
Me.faceRotation = newRotation
End If
End If
End If
Else
Dim CanRotate As Boolean = False
For Each r As Rectangle In Me.MoveRectangles
If r.Contains(New Point(CInt(newPosition.X), CInt(newPosition.Z))) = True Then
CanRotate = True
Exit For
End If
Next
If CanRotate = True Then
Me.faceRotation = newRotation
End If
End If
End If
Else
Dim CanRotate As Boolean = False
For Each r As Rectangle In Me.MoveRectangles
If r.Contains(New Point(CInt(newPosition.X), CInt(newPosition.Z))) = True Then
CanRotate = True
Exit For
End If
Next
If CanRotate = True Then
Me.faceRotation = newRotation
End If End If
End If End If
End If End If
@ -790,35 +797,34 @@
newPosition = New Vector3(CInt(newPosition.X), CInt(newPosition.Y), CInt(newPosition.Z)) newPosition = New Vector3(CInt(newPosition.X), CInt(newPosition.Y), CInt(newPosition.Z))
Dim oldPosition As Vector3 = Me.Position Dim oldPosition As Vector3 = Me.Position
Dim interactPlayer As Boolean = True Dim interactPlayer As Boolean = False
If Screen.Camera.IsMoving() = False Then If Screen.Camera.IsMoving() = False Then
If CInt(Screen.Camera.Position.X) <> newPosition.X Or CInt(Screen.Camera.Position.Z) <> newPosition.Z Then If CInt(Screen.Camera.Position.X) = newPosition.X And CInt(Screen.Camera.Position.Z) = newPosition.Z Then
If CInt(Screen.Level.OverworldPokemon.Position.X) <> newPosition.X Or CInt(Screen.Level.OverworldPokemon.Position.Z) <> newPosition.Z Then If CInt(Screen.Level.OverworldPokemon.Position.X) = newPosition.X And CInt(Screen.Level.OverworldPokemon.Position.Z) = newPosition.Z Then
interactPlayer = False interactPlayer = True
End If End If
End If End If
Else Else
Dim cameraNewPosition As Vector3 = Screen.Camera.GetForwardMovedPosition() Dim cameraNewPosition As Vector3 = CType(Screen.Camera, OverworldCamera).LastStepPosition + Screen.Camera.PlannedMovement()
Dim cameraOldPosition As Vector3 = Screen.Camera.GetForwardMovedPosition() - Screen.Camera.GetMoveDirection() If CInt(cameraNewPosition.X) = newPosition.X And CInt(cameraNewPosition.Z) = newPosition.Z Then
If CInt(cameraNewPosition.X) <> newPosition.X And CInt(cameraOldPosition.X) <> newPosition.X Or CInt(cameraNewPosition.Z) <> newPosition.Z And CInt(cameraOldPosition.Z) <> newPosition.Z Then If CInt(Screen.Level.OverworldPokemon.Position.X) = newPosition.X And CInt(Screen.Level.OverworldPokemon.Position.Z) = newPosition.Z Then
If CInt(Screen.Level.OverworldPokemon.Position.X) <> newPosition.X Or CInt(Screen.Level.OverworldPokemon.Position.Z) <> newPosition.Z Then interactPlayer = True
interactPlayer = False
End If End If
End If End If
End If End If
'' check if a NetworkPlayer is not in the way '' check if a NetworkPlayer is not in the way
For Each Player As NetworkPlayer In Screen.Level.NetworkPlayers For Each Player As NetworkPlayer In Screen.Level.NetworkPlayers
If CInt(Player.Position.X) <> newPosition.X And CInt(Player.Position.Z) <> newPosition.Z Then If CInt(Player.Position.X) = newPosition.X And CInt(Player.Position.Z) = newPosition.Z Then
interactPlayer = False interactPlayer = True
Exit For Exit For
End If End If
Next Next
'' check if a NetworkPokémon is not in the way '' check if a NetworkPokémon is not in the way
For Each Pokemon As NetworkPokemon In Screen.Level.NetworkPokemon For Each Pokemon As NetworkPokemon In Screen.Level.NetworkPokemon
If CInt(Pokemon.Position.X) <> newPosition.X And CInt(Pokemon.Position.Z) <> newPosition.Z Then If CInt(Pokemon.Position.X) = newPosition.X And CInt(Pokemon.Position.Z) = newPosition.Z Then
interactPlayer = False interactPlayer = True
Exit For Exit For
End If End If
Next Next

View File

@ -859,19 +859,30 @@ Public Class OverworldCamera
setSurfFalse = True setSurfFalse = True
End If End If
Next Next
Dim PlayerBoundingBox As New BoundingBox(
newPosition + New Vector3(-0.465F),
newPosition + New Vector3(0.465F))
If cannotWalk = False Then If cannotWalk = False Then
For Each Entity As Entity In Screen.Level.Entities For Each Entity As Entity In Screen.Level.Entities
If Entity.boundingBox.Contains(Position2D) = ContainmentType.Contains Then If Entity.EntityID.ToLower = "npc" Then
If cannotWalk = False Then If Entity.ViewBox.Contains(PlayerBoundingBox) = ContainmentType.Intersects Then
If Entity.Collision = True Then If Entity.Collision = True Then
cannotWalk = Entity.WalkAgainstFunction() cannotWalk = Entity.WalkAgainstFunction()
Else Else
cannotWalk = Entity.WalkIntoFunction() cannotWalk = Entity.WalkIntoFunction()
End If End If
End If End If
ElseIf Entity.boundingBox.Contains(New Vector3(Position2D.X, Position2D.Y - 1, Position2D.Z)) = ContainmentType.Contains Then Else
Entity.WalkOntoFunction() If Entity.boundingBox.Contains(Position2D) = ContainmentType.Contains Then
If Entity.Collision = True Then
cannotWalk = Entity.WalkAgainstFunction()
Else
cannotWalk = Entity.WalkIntoFunction()
End If
ElseIf Entity.boundingBox.Contains(New Vector3(Position2D.X, Position2D.Y - 1, Position2D.Z)) = ContainmentType.Contains Then
Entity.WalkOntoFunction()
End If
End If End If
Next Next
Else Else