вот теория как в школе учили через длинну (a и b) найти косинус а потом арккосинус
светильники это waypoint
проблема в том что шарик поворачивается не правельно
Синтаксис:
Используется javascript
var Way:Transform;
var Sphere:Transform;
private var VertexX:float;
private var VertexZ:float;
var Point:int;
var a:float;
var b:float;
var first:boolean;
function Update(){
if(Vector3.Distance(Sphere.position,Way.GetChild(Point).position)<2){
Point=Point+1;
first=true;
}
Sphere.rotation.y=Angle(first);
Sphere.Translate(0.05,0,0);
}
function Angle(f:boolean){
VertexX = Sphere.position.x;
VertexZ = Way.GetChild(Point).position.z;
a=Mathf.Sqrt(MathfSqr(VertexX-Sphere.position.x)+MathfSqr(VertexZ-Sphere.position.z));
b=Mathf.Sqrt(MathfSqr(Way.GetChild(Point).position.x-Sphere.position.x)+MathfSqr(Way.GetChild(Point).position.z-Sphere.position.z));
v=Mathf.Acos(Mathf.Cos(a/b));
if(f==true){
return v;
first=false;
}
}
function MathfSqr(x:float){
x=x*x;
return x;
}
var Sphere:Transform;
private var VertexX:float;
private var VertexZ:float;
var Point:int;
var a:float;
var b:float;
var first:boolean;
function Update(){
if(Vector3.Distance(Sphere.position,Way.GetChild(Point).position)<2){
Point=Point+1;
first=true;
}
Sphere.rotation.y=Angle(first);
Sphere.Translate(0.05,0,0);
}
function Angle(f:boolean){
VertexX = Sphere.position.x;
VertexZ = Way.GetChild(Point).position.z;
a=Mathf.Sqrt(MathfSqr(VertexX-Sphere.position.x)+MathfSqr(VertexZ-Sphere.position.z));
b=Mathf.Sqrt(MathfSqr(Way.GetChild(Point).position.x-Sphere.position.x)+MathfSqr(Way.GetChild(Point).position.z-Sphere.position.z));
v=Mathf.Acos(Mathf.Cos(a/b));
if(f==true){
return v;
first=false;
}
}
function MathfSqr(x:float){
x=x*x;
return x;
}