Linecast and Joystick on GridGraph


I encountered with a problem when using Linecast in the GridGenerator.cs class GridGraph. In example Example9_Penalties I changed in the script TargetMover.cs class TargetMover function UpdateTargetPosition

[details=Edit TargetMover UpdateTargetPosition]> public void UpdateTargetPosition () {
Vector3 newPosition =;
bool positionFound = false;

float velocity = 1f;
var directionPosition =;
if (Input.GetKey("w"))
	directionPosition += new Vector3(0, 0, velocity);
if (Input.GetKey("a"))
	directionPosition += new Vector3(-velocity, 0, 0);
if (Input.GetKey("s"))
	directionPosition += new Vector3(0, 0, -velocity);
if (Input.GetKey("d"))
	directionPosition += new Vector3(velocity, 0, 0);

if (directionPosition !=
	var graph =[0];
	var updateGraph = graph as IRaycastableGraph;
	GraphHitInfo hit;
	List<GraphNode> trace = new List<GraphNode>();
	bool result = updateGraph.Linecast(target.position, target.position + directionPosition, null, out hit, trace);
	newPosition = hit.point;
	positionFound = true;


to using WASD to move himself gameObject Target, not using spiders-bot. In the end, the Linecast in the direction from right to left and from top to bottom works well (,
in the opposite direction the target is in an impassable area and gets stuck there ( (inside the Linecast() it enters in condition (!startNode.Walkable) {…return true;}) I use A* Pathfinding Project Pro 4.1.7 (branch beta) and Unity 2017.1.2p2. (I have downloaded)
I have to check the result Linecast() and if it`s true - to do the offset in the direction of movement. Yesterday released version 4.1.8 Pro, but I haven’t tried.

The task to try a movement on joystick on the grid. I havent found any good information about this in Internet, and I’m not sure that this can be done adequately on a grid and most likely
will have to use Navmesh/Recast, which uses precise geometry of the world. What do you think, Is it worth to experiment with the grid or directly use Navmesh/Recast? If the Linecast I can handle with offsetting
how to make a smooth glide I don’t know.


I would do something like this every frame:

transform.position =, NNConstraint.Default).position;

That will move the character to the closest walkable point on the graph to its current position. It will also give you a decent sliding behavior.