Fix Walk NPC Movement...
Now an NPC with the Walk MovementType will no longer face a direction that is not in its MoveRectangles. When blocked in all directions, it will turn towards a place where it would otherwise have moved towards. Also slightly changed the chance for the NPC to walk or change direction.
This commit is contained in:
parent
3d44bf61f3
commit
5c3adbcb2a
|
@ -586,25 +586,53 @@
|
||||||
End If
|
End If
|
||||||
Case Movements.Walk
|
Case Movements.Walk
|
||||||
If Me.Moved = 0.0F Then
|
If Me.Moved = 0.0F Then
|
||||||
If Core.Random.Next(0, 120) = 0 Then
|
If Core.Random.Next(0, 129) = 0 Then
|
||||||
|
Dim newRotation As Integer = Me.faceRotation
|
||||||
If Core.Random.Next(0, 3) = 0 Then
|
If Core.Random.Next(0, 3) = 0 Then
|
||||||
Dim newRotation As Integer = Me.faceRotation
|
|
||||||
While newRotation = Me.faceRotation
|
While newRotation = Me.faceRotation
|
||||||
newRotation = Core.Random.Next(0, 4)
|
newRotation = Core.Random.Next(0, 4)
|
||||||
End While
|
End While
|
||||||
Me.faceRotation = newRotation
|
|
||||||
End If
|
End If
|
||||||
Dim contains As Boolean = False
|
Dim newPosition As Vector3 = (GetMove(newRotation) / Speed) + Me.Position
|
||||||
Dim newPosition As Vector3 = (GetMove() / Speed) + Me.Position
|
Dim canMove As Boolean = False
|
||||||
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 AndAlso CheckCollision(newPosition) = True Then
|
||||||
|
canMove = True
|
||||||
|
Exit For
|
||||||
|
End If
|
||||||
|
Next
|
||||||
|
Dim CanRotate As New List(Of Integer)
|
||||||
|
While canMove = False
|
||||||
|
newRotation += 1
|
||||||
|
If newRotation > 3 Then
|
||||||
|
newRotation -= 4
|
||||||
|
End If
|
||||||
|
newPosition = (GetMove(newRotation) / Speed) + Me.Position
|
||||||
For Each r As Rectangle In Me.MoveRectangles
|
For Each r As Rectangle In Me.MoveRectangles
|
||||||
If r.Contains(New Point(CInt(newPosition.X), CInt(newPosition.Z))) = True Then
|
If r.Contains(New Point(CInt(newPosition.X), CInt(newPosition.Z))) = True Then
|
||||||
contains = True
|
If CheckCollision(newPosition) = True Then
|
||||||
Exit For
|
canMove = True
|
||||||
|
Exit While
|
||||||
|
Else
|
||||||
|
If CanRotate.Contains(newRotation) = False AndAlso newRotation <> Me.faceRotation Then
|
||||||
|
CanRotate.Add(newRotation)
|
||||||
|
End If
|
||||||
|
End If
|
||||||
End If
|
End If
|
||||||
Next
|
Next
|
||||||
If contains = True Then
|
If newRotation = Me.faceRotation Then
|
||||||
Moved = 1.0F
|
Exit While
|
||||||
|
End If
|
||||||
|
End While
|
||||||
|
|
||||||
|
Me.faceRotation = newRotation
|
||||||
|
|
||||||
|
If canMove = True Then
|
||||||
|
Moved = 1.0F
|
||||||
|
Else
|
||||||
|
If CanRotate.Count > 0 Then
|
||||||
|
Me.faceRotation = CanRotate(Random.Next(0, CanRotate.Count))
|
||||||
End If
|
End If
|
||||||
End If
|
End If
|
||||||
End If
|
End If
|
||||||
|
|
Loading…
Reference in New Issue