i found this application made with unity3D and i need help to know the way that i must be in.(sorry for my English)
The question is how can i switch from 2D lines to 3D cube interface?
thanks for help :)))
link text
I think this algorithm can do what you want: when the player starts recording a path, each time the distance from the last point saved reaches a limit, a new point is added. It continues until a predefined number of waypoints is reached. While adding points, cubes are added connecting each point to the previous.
This script does this: create an empty object, attach this script to it and set the player variable to your player; press āpā to delete the path and start recording a new one.
var player: Transform; // drag the player here, or find it at Start
var wpDistance: float = 6; // distance between waypoints
var maxWaypoints: int = 20; // number of waypoints to create
private var waypoints = new Vector3[0];
private var cubes = new GameObject[0];
private var curWP = 0;
private var lastWP: Vector3;
private var recording = false;
function AddPoint(){
var n = curWP;
curWP += 1;
waypoints[n] = player.position;
if (n > 0){
// create cube
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
// cube placed between 2 last waypoints
cube.transform.position = (player.position+lastWP)/2;
// get difference between 2 last waypoints
var dir = player.position-lastWP;
// rotate cube to the correct direction
cube.transform.forward = dir.normalized;
// adjust length and set width to 2x2
var scale = Vector3(2, 2, dir.magnitude);
cube.transform.localScale = scale;
cubes[n] = cube;
}
lastWP = player.position;
}
// call this function to initiate a new path:
function ResetPath(){
for (var i=0; i < cubes.length; i++){
if (cubes_) Destroy(cubes*);*_
_* }*_
_*waypoints = new Vector3[maxWaypoints];*_
_* cubes = new GameObject[maxWaypoints];*_
_*curWP = 0;*_
_* recording = true;*_
_* AddPoint();*_
_*}*_
_*// call this at Update while creating a new path -*_
_*// recording becomes false when path finished*_
_*function RecordPath(){*_
_* if (curWP < maxWaypoints){*_
_* var dist = Vector3.Distance(player.position, lastWP);*_
_* if (dist >= wpDistance) AddPoint();*_
_* }*_
_* else {*_
_* recording = false;*_
_* }*_
_*}*_
_*function Update(){*_
_* if (Input.GetKeyDown("p")){*_
_* ResetPath(); // delete old path and start recording*_
_* }*_
_* if (recording){ // while path not ready...*_
_* RecordPath(); // record path*_
_* }*_
_*}*_
_**_