SpikeL Comunidad
Hola, bienvenido a SpikeL Foro.

Si eres nuevo, deves registrarte.

Si ya tienes una cuenta, deves ingresar.

¡Muchas gracias!

PD: Si te has registrado pero no puedes logear tienes que activar tu cuenta desde tu e-mail.


Unirse al foro, es rápido y fácil

SpikeL Comunidad
Hola, bienvenido a SpikeL Foro.

Si eres nuevo, deves registrarte.

Si ya tienes una cuenta, deves ingresar.

¡Muchas gracias!

PD: Si te has registrado pero no puedes logear tienes que activar tu cuenta desde tu e-mail.
SpikeL Comunidad
¿Quieres reaccionar a este mensaje? Regístrate en el foro con unos pocos clics o inicia sesión para continuar.

Npc´s esquivan colisiones

Ir abajo

Npc´s esquivan colisiones Empty Npc´s esquivan colisiones

Mensaje por Francohhh Dom Feb 27, 2011 12:46 pm

Bueno empezemos.

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.


o.o.O.O
[Tienes que estar registrado y conectado para ver este vínculo]spikel.org
Francohhh
Francohhh
Administrador
Administrador

Administrador
Medallas
Npc´s esquivan colisiones Prensa1Npc´s esquivan colisiones Fundador1Npc´s esquivan colisiones Participativo1Npc´s esquivan colisiones Donar1
Npc´s esquivan colisiones Staff1x Npc´s esquivan colisiones Moderador1 Npc´s esquivan colisiones Ao1 Npc´s esquivan colisiones Desarrollo
Npc´s esquivan colisiones Radio10 Npc´s esquivan colisiones Radio110 Npc´s esquivan colisiones Colabo10 Npc´s esquivan colisiones Progra10
Npc´s esquivan colisiones Cs110Npc´s esquivan colisiones Postea10 Npc´s esquivan colisiones Senor_10 Npc´s esquivan colisiones Dueno_10
Npc´s esquivan colisiones Futbol10

Mensajes Mensajes : 880
Puntos Puntos : 53086
Reputación Reputación : 41
Sexo Sexo : Masculino

Fecha de inscripción Fecha de inscripción : 23/03/2010
Edad Edad : 27
Localización Localización : Mar del Plata

http://www.spikel.org

Volver arriba Ir abajo

Volver arriba


 
Permisos de este foro:
No puedes responder a temas en este foro.