- Home /
Question by
raqbiel · Aug 14, 2019 at 10:31 AM ·
procedural generationwaypointsnodesroad
Create Procedural Road with nodes in direction
Hello!
I wanna create road using nodes. Everytime when I meet node on road script creating new node on the end of my road and creating new part of road between nodes. I want to creating nodes with random position but in direction to point B(check screen). Someone could help me how i could do that?:) Sorry for my english :)
Script for generate new node after meet node:
private void OnTriggerExit(Collider other)
{
float currentOffset = 150f;
if (other.gameObject.name == "Cube") {
Debug.Log("Triggered");
Transform lastItem = procRoad.pathNodes[procRoad.pathNodes.Count - 1];
//Transform firstItem = procRoad.pathNodes[0];
Vector3 localOffset = new Vector3(Random.Range(-150,150), 0, currentOffset); //offset for first road block
Vector3 spawnPosition = lastItem.transform.position + localOffset;
GameObject go = Instantiate(procRoad.nodePrefab, spawnPosition, Quaternion.identity) as GameObject;
MoveNodes moveNode = go.AddComponent<MoveNodes>();
moveNode.Init(raycastCamera, heightOffset, procRoad);
procRoad.pathNodes.Add(go.transform);
this.gameObject.SetActive(false);
if (procRoad.pathNodes.Count > 1)
{
procRoad.RegenerateAuxNodes();
}
if(procRoad.pathNodes.Count > 10)
{
// Destroy(transform.gameObject);
procRoad.pathNodes.Remove(procRoad.pathNodes[0]);
}
}
Thanks guys!
waypoints.png
(10.4 kB)
Comment
Your answer
Follow this Question
Related Questions
PacMan IA of ghost using nodes/waypoints 0 Answers
Generating sectors around nodes 0 Answers
Help understanding pathfinding 0 Answers
Problems with my waypoints code 1 Answer
AI Character spins around Waypoint 1 Answer