I want to make a very simple script that gonna do only that, show how far it is to the target using A* pathfinding, i am a complete noob at coding so explanation would be appreciated.
This can give you good start.
Seeker.StartPath(start, target, OnPathCalculated, graphMask);
void OnPathCalculated(Path path){
if(path.error){
return;
}
float pathLength = path.GetTotalLength()
}
Edit:I have assumed you are using A* Pathfinding by aron granberg.
yes, i using that asset, but the free version of it
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Pathfinding;
public class PFing : MonoBehaviour
{
Seeker.StartPath(start, target, OnPathCalculated, graphMask);
void OnPathCalculated(Path path)
{
if (path.error)
{
return;
}
float pathLength = path.GetTotalLength()
}
}
for every field in this “Seeker.StartPath(start, target, OnPathCalculated, graphMask);” line it tells me that “it does not exist in the current context” what am i missing?
Ok i see you are real beginner.
Try this.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Pathfinding;
public class PFing : MonoBehaviour
{
public Seeker seeker;
void Start(){
seeker.StartPath(start, target, OnPathCalculated);
}
void OnPathCalculated(Path path)
{
if (path.error)
{
return;
}
float pathLength = path.GetTotalLength()
}
}
huh, is it supposed to return length in console instead of public float or am i missing something?
May I ask what are you need it for ?
Because it looks like your programming skill is “Hello World” level.
And it might be good idea to start with a basics.
i make an xcom like game and want to get the path length to see if it’s more or less then a treshold to spawn a tile that player can click on, and i use playmaker so most of the logic i made in it, but there is no action for astar to get the length of the path which is the crucial for field of movement visualization, i managed to make it with unity navmesh but it’s too slow, so i need astar
and yes, my coding skills are low, i do understand principles but my problem is syntax and what even can i do, and i have no clue where to look for things i need, i look at astar documentation but it’s just confusing for me
I will not help you with playmaker and how to grab data from component to playmaker since I don’t use it.
But since it is a turn based game and you are just a beginner I suggest using:
var path = Pathfinding.ABPath.Construct(start, end);
AstarPath.BlockUntilCalculated(path);
This will block thread until path is completed.
where can i found an extensive explanation on astar functions? i tried to google what “path.GetTotalLength” actually do, but all the documentations i found doesn’t really tell much
You are joking, right ?
Here is a documentation:
https://arongranberg.com/astar/docs/
oh, there were a search bar… didn’t saw it for all this time for some reason