Npc´s esquivan colisiones
Página 1 de 1.
Npc´s esquivan colisiones
Bueno empezemos.
El código es 100% funcional...
Server.
Buscamos:
Y lo remplazamos por:
Buscamos:
Y lo remplazamos por:
Buscamos:
Y remplazamos todo el sub (HASTA END SUB):
Fuente: GS-ZONE.
Autor: kshamitohh.
[Tienes que estar registrado y conectado para ver este vínculo]spikel.org
El código es 100% funcional...
Server.
Buscamos:
- Código:
tHeading = FindDirection(.Pos, UserList(OwnerIndex).Pos)
Call MoveNPCChar(NpcIndex, tHeading)
Y lo remplazamos por:
- Código:
'Esquiva colisiones
If Not .PFINFO.PathLenght > 0 Then tHeading = FindDirection(.Pos, UserList(OwnerIndex).Pos)
If tHeading = 0 Then
If ReCalculatePath(NpcIndex) Then
Call PathFindingAI(NpcIndex)
'Existe el camino?
If .PFINFO.NoPath Then 'Si no existe nos movemos al azar
'Move randomly
Call MoveNPCChar(NpcIndex, RandomNumber(eHeading.NORTH, eHeading.WEST))
End If
Else
If Not PathEnd(NpcIndex) Then
Call FollowPath(NpcIndex)
Else
.PFINFO.PathLenght = 0
End If
End If
Else
If Not .PFINFO.PathLenght > 0 Then Call MoveNPCChar(NpcIndex, tHeading)
Exit Sub
End If
Buscamos:
- Código:
tHeading = FindDirection(Npclist(NpcIndex).Pos, .Pos)
Call MoveNPCChar(NpcIndex, tHeading)
Y lo remplazamos por:
- Código:
'Esquiva colisiones
If Not Npclist(NpcIndex).PFINFO.PathLenght > 0 Then tHeading = FindDirection(Npclist(NpcIndex).Pos, .Pos)
If tHeading = 0 Then
If ReCalculatePath(NpcIndex) Then
Call PathFindingAI(NpcIndex)
'Existe el camino?
If Npclist(NpcIndex).PFINFO.NoPath Then 'Si no existe nos movemos al azar
'Move randomly
Call MoveNPCChar(NpcIndex, RandomNumber(eHeading.NORTH, eHeading.WEST))
End If
Else
If Not PathEnd(NpcIndex) Then
Call FollowPath(NpcIndex)
Else
Npclist(NpcIndex).PFINFO.PathLenght = 0
End If
End If
Else
If Not Npclist(NpcIndex).PFINFO.PathLenght > 0 Then Call MoveNPCChar(NpcIndex, tHeading)
Exit Sub
End If
Buscamos:
- Código:
Function FindDirection(Pos As WorldPos, Target As WorldPos) As eHeading
Y remplazamos todo el sub (HASTA END SUB):
- Código:
Function FindDirection(Pos As WorldPos, Target As WorldPos) As eHeading
'***************************************************
'Author: Unknown
'Last Modification: - Kshamenk 23/2/11
'Devuelve la direccion en la cual el target se encuentra
'desde pos, 0 si la direc es igual o hay un bloqueo
'*****************************************************************
Dim X As Integer
Dim Y As Integer
X = Pos.X - Target.X
Y = Pos.Y - Target.Y
'NE
If Sgn(X) = -1 And Sgn(Y) = 1 Then
FindDirection = IIf(RandomNumber(0, 1), eHeading.NORTH, eHeading.EAST)
If Not LegalPos(Pos.Map, Pos.X - Sgn(X), Pos.Y - Sgn(Y)) Then FindDirection = 0
Exit Function
End If
'NW
If Sgn(X) = 1 And Sgn(Y) = 1 Then
FindDirection = IIf(RandomNumber(0, 1), eHeading.WEST, eHeading.NORTH)
If Not LegalPos(Pos.Map, Pos.X - Sgn(X), Pos.Y - Sgn(Y)) Then FindDirection = 0
Exit Function
End If
'SW
If Sgn(X) = 1 And Sgn(Y) = -1 Then
FindDirection = IIf(RandomNumber(0, 1), eHeading.WEST, eHeading.SOUTH)
If Not LegalPos(Pos.Map, Pos.X - Sgn(X), Pos.Y - Sgn(Y)) Then FindDirection = 0
Exit Function
End If
'SE
If Sgn(X) = -1 And Sgn(Y) = -1 Then
FindDirection = IIf(RandomNumber(0, 1), eHeading.SOUTH, eHeading.EAST)
If Not LegalPos(Pos.Map, Pos.X - Sgn(X), Pos.Y - Sgn(Y)) Then FindDirection = 0
Exit Function
End If
'Sur
If Sgn(X) = 0 And Sgn(Y) = -1 Then
FindDirection = eHeading.SOUTH
If Not LegalPos(Pos.Map, Pos.X - Sgn(X), Pos.Y - Sgn(Y)) Then FindDirection = 0
Exit Function
End If
'norte
If Sgn(X) = 0 And Sgn(Y) = 1 Then
FindDirection = eHeading.NORTH
If Not LegalPos(Pos.Map, Pos.X - Sgn(X), Pos.Y - Sgn(Y)) Then FindDirection = 0
Exit Function
End If
'oeste
If Sgn(X) = 1 And Sgn(Y) = 0 Then
FindDirection = eHeading.WEST
If Not LegalPos(Pos.Map, Pos.X - Sgn(X), Pos.Y - Sgn(Y)) Then FindDirection = 0
Exit Function
End If
'este
If Sgn(X) = -1 And Sgn(Y) = 0 Then
FindDirection = eHeading.EAST
If Not LegalPos(Pos.Map, Pos.X - Sgn(X), Pos.Y - Sgn(Y)) Then FindDirection = 0
Exit Function
End If
'misma
If Sgn(X) = 0 And Sgn(Y) = 0 Then
FindDirection = 0
Exit Function
End If
End Function
Fuente: GS-ZONE.
Autor: kshamitohh.
[Tienes que estar registrado y conectado para ver este vínculo]spikel.org
Página 1 de 1.
Permisos de este foro:
No puedes responder a temas en este foro.
|
|