Hi,
I am making a JS which builds a random race road for my game,
It uses a prefab pieces of roads to build the road an shown :
My problem now that sometimes blocks interferes with each other :
I want to know what is your opinions on solving this problem, how can i detect the surrounding?
Concept of solution is enough but i would appreciate a script references for the solution.
Note : This is not an infinite road but it will be built once only, so i can’t destroy the blocks because other player vehicles could be on them.
This is my current code :
#pragma strict
private var Me : Transform;
var Sections : int;
var SectionBlockNo : int;
@Range(0,100) var TurnPer : int;
var BeginPieces : Transform[];
var StraightPieces : Transform[];
var TurnPieces : Transform[];
var SpecialPieces : Transform[];
function Awake ()
{
Me = transform;
Level ();
}
function Level ()
{
MakeLevel(SectionBlockNo);
}
function MakeLevel (BlockNo : int)
{
var InstPosition : Vector3;
var Piece : Transform;
var NewPiece : Transform;
var RoadPiece : RoadPiece;
Piece = BeginPieces.GetValue(Random.Range(0,BeginPieces.Length));
NewPiece = Instantiate (Piece , Me.position , Me.rotation);
RoadPiece = NewPiece.gameObject.GetComponent("RoadPiece");
Me.position = RoadPiece.EndPoint.position;
Me.rotation = RoadPiece.EndPoint.rotation;
for (var i : int = 0; i < BlockNo;i++)
{
var RandomChance : int = Random.Range(0,100);
if(RandomChance >= TurnPer)
{
Piece = StraightPieces.GetValue(Random.Range(0,StraightPieces.Length));
}
else
{
Piece = TurnPieces.GetValue(Random.Range(0,TurnPieces.Length));
}
NewPiece = Instantiate (Piece , Me.position , Me.rotation);
RoadPiece = NewPiece.gameObject.GetComponent("RoadPiece");
Me.position = RoadPiece.EndPoint.position;
Me.rotation = RoadPiece.EndPoint.rotation;
}
}

