Noticias

¡RECUERDA QUE SI ERES UN NUEVO USUARIO, DEBES PRESENTARTE PARA PODER PUBLICAR MENSAJES! | TENEMOS CANAL OFICIAL DE TELEGRAM: t.me/unity3dspain

Path finding unity2d

Iniciado por Ness, Octubre 10, 2015, 01:16:25 AM

Tema anterior - Siguiente tema
hola presento un inconveniente para  un juego que estoy haciendo en 2d necesito que un objeto siga a otro y que esquive obstáculos para que llegue donde el esta el objetivo sin utilizar waypoints pero al parecer navimesh solo trabaja con unity3d por lo que no se si hay alguna manera de hacerlo en 2d.mi pregunta es hay alguna manera de que el objeto llegue al objetivo esquivando los obstáculo?, por hay investigue tutoriales de  Pathfinding para unity2d pero al parecer están desactualizados con la version 5 alguno conocera algun tuto para unity5 o algún script para estudiarlo. Gracias por su tiempo.

Octubre 10, 2015, 03:30:03 AM #1 Ultima modificación: Octubre 10, 2015, 03:31:17 AM por nestorjaviersolera
BUENO VOY  PUBLICANDO LOS RESULTADOS DE LO QUE VALLA ENCONTRANDO.ESTE ASSET ES MUY INTERESANTA Y ES GRATIS.https://www.assetstore.unity3d.com/en/#!/content/20087">https://www.assetstore.unity3d.com/en/#!/content/20087SI ALGUIEN TIENE ALGUNA OTRA INFORMACIÓN SE LOS AGRADECERÍA.

Hola me encontré este código según entiendo es scritp es una código para la version 4.5.0 de unity. cuando lo compilo en versiones superiores este me genera conflicto quisiera saber como solucionar el problema que al parecer que no me detecta ciertas variables. gracias  ademas todo el agradecimiento a http://hobblygobbly.tumblr.com/
using UnityEngine;
using System.Collections;
//Note this line, if it is left out, the script won't know that the class 'Path' exists and it will throw compiler errors
//This line should always be present at the top of scripts which use pathfinding
using Pathfinding;

public class AstarAI : MonoBehaviour
{
  //The point to move to
  public Transform target;

  private Seeker seeker;

  //The calculated path
  public Path path;

  //The AI's speed per second
  public float speed = 2;

  //The max distance from the AI to a waypoint for it to continue to the next waypoint
  public float nextWaypointDistance = 3;

  //The waypoint we are currently moving towards
  private int currentWaypoint = 0;

  public void Start ()
  {
    seeker = GetComponent<Seeker>();

    //Start a new path to the targetPosition, return the result to the OnPathComplete function
    seeker.StartPath( transform.position, target.position, OnPathComplete );
  }

  public void OnPathComplete ( Path p )
  {
    Debug.Log( "Yay, we got a path back. Did it have an error? " + p.error );
    if (!p.error)
    {
      path = p;
      //Reset the waypoint counter
      currentWaypoint = 0;
    }
  }

  public void FixedUpdate ()
  {
    if (path == null)
    {
      //We have no path to move after yet
      return;
    }

    if (currentWaypoint >= path.vectorPath.Count)
    {
      Debug.Log( "End Of Path Reached" );
      return;
    }

    //Direction to the next waypoint
    Vector3 dir = ( path.vectorPath[ currentWaypoint ] - transform.position ).normalized;
    dir *= speed * Time.fixedDeltaTime;
    this.gameObject.transform.Translate( dir );

    //Check if we are close enough to the next waypoint
    //If we are, proceed to follow the next waypoint
    if (Vector3.Distance( transform.position, path.vectorPath[ currentWaypoint ] ) < nextWaypointDistance)
    {
      currentWaypoint++;
      return;
    }
  }
}
  

Octubre 10, 2015, 07:23:56 AM #3 Ultima modificación: Octubre 10, 2015, 08:00:34 AM por nestorjaviersolera
solucion gente usen unity 5 para que no les tire error estaba haciendo la prueba con unity4.5 y no me detentaba el (using Pathfinding; ) porque mi version no es pro. (Y) 


Hay un botón maravilloso para editar tu post, te recomiendo que lo uses para la próxima vez

Etiquetas: