To see how the character navigates around, here is a short video,
As you can see, when you click on a node, character finds its path to it and walks along the path. I can draw up my own map, save it in PNG and import it into Unity but I am not sure where to go from there. Do I lay on top of the map image, some game objects as the nodes to listen to click events? How do I force my character to walk only on the paths of the map?
I’ve not had to solve this mechanic yet, although I will in the near future. Have you looked into Navmesh? It might be what you are looking for. Also there are some light weight point to point nav agents in the asset store that might be helpful.
The underlined red is where the animation happens. However this code results in something like the following animation where the character pauses in between the dots.
I want the character to follow this path in one smooth motion without any intermittent pauses.
Could somebody help?
The reason you’re getting that segmented motion is because you’re lerping from your position which changes every Update. Think of it like this; you want your character to move some fraction of the distance between point A and point B a given number of times until it reaches the destination. But you’re actually telling it, move some fraction of a distance from where it currently is to point B. What you need to do is create another class level Vector2 variable called startPosition or something like that, then in your CheckNode() function add…startPosition = Player.transform.position;And in Update, change your lerp call to…Player.transform.position = Vector3.Lerp(startPosition, CurrentPositionHolder, Timer);
I haven’t tested that but it should work.
Yes - several ways - change the pivot of the sprite either in Unity or authoring tool, or parent the character to a game object placed where you want the pivot to be.
Some documentation research - might help going forward.
The above code works fine… here i pasted my code for reference.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PathFollower : MonoBehaviour {
public GameObject[ ] PathNode;
public GameObject Player;
public float MoveSpeed;
float Timer;
static Vector3 CurrentPositionHolder;
int CurrentNode;
private Vector2 startPosition;
// Use this for initialization
void Start () {
//PathNode = GetComponentInChildren<>();
CheckNode ();
}
Hi! Do you know how can I move my character inside this type of path? I mean, I don’t want him to follow it from start to end. I want to make like a path grid and move through a ball .