Hi all,
Starting to go insane and have killed too much trying so now hopefully some good people can help me out!
Just trying to create a map where the player can click on a node (cylinder\circle) adjacent to where they are and move to it. Some Nodes go direct to each other but some nodes you have a choice, highlighted in red.
But instead how I have it setup is I can click on any node and it goes straight to it in a straight line, highlighted in blue.
The purple vector lines are for the viewport so I can see which nodes you can move between, they are just a guide. Mind you it’d be great in the GamePlayer (Cube that is selected) could follow that line too.
I have a script attached to the Route parent and nodes as children, and to the GamePlayer parent for the cube.
Any guidance or tutorials for this?
I followed this tutorial to start, but really need\want the functionality of clicking and moving to any adjacent Node only.
If you want the player to input the sequence of moves they will do, then you need some type of stateful input gathering mechanism that accumulates your clicks into a list, checks for validity, then considers it complete either when you say or when you reach the goal.
You would perhaps want a way to back up one link, or to escape and quit all input, start over, and perhaps a way to confirm: “hey, this is the path you just put in… do you want to do it now?”
Thanks for your response @Kurt-Dekker
The way I have laid it out is pretty much the same as the boardgame YT clip above, do you think this is the right approach?
It sounds like you want to represent this play area as a graph. Each node can contain a list of other nodes that it is directly connected to. When the user clicks on a node, you only allow the movement if the selected node is on the list of directly connected nodes for the current position.
public class GameNode : MonoBehaviour
{
//If all links are bi-directional, then you only need one list of connected nodes
[SerializeField] List<GameNode> outgoing;
[SerializeField] List<GameNode> incoming;
public bool CanIMoveHere(GameNode node)
{
return outgoing.Contains(node);
}
}
You could also implement the graph structure as a separate, non-MonoBehaviour entity and use that to validate the game rules. You will still need a way to associate the nodes in such a graph to the actual game objects in your scene.