I am trying to understand the problem a posted previously - see attached image. I understand one solution but just want to understand why my script below wont solve it. The radius of the sphere is 5 ie .5 collider radius * scale(10) The model does not end up on the perimeter of the sphere where I assume it would - just off of the center of the sphere perim is the "circle" around the model. I divide this by 360 degrees (deg) then offset this by the radius of the sphere (radcirc). Then convert this to radians which are applied via Sine and Cosine. function Start (){ dist = Vector3.Distance(other.position, transform.position); perim = (2*dist)*Mathf.PI; deg = perim/360; radcirc = 5*deg; } function Update () { mover();} function mover () { rad = radcirc* Mathf.Deg2Rad; transform.position = Vector3(0,0,0) + Vector3(dist*Mathf.Sin(rad),0, dist*Mathf.Cos(rad)); }
your problem, as far as I understand your description, is Code (csharp): transform.position = Vector3(0,0,0) + Vector3(dist*Mathf.Sin(rad),0, dist*Mathf.Cos(rad)); 1. Instead of Vector3(0,0,0) you likely wanted to use transform.position to use the current center of the model 2. Vector3( ..., 0, ... ); potentially is missing * dist, you currently move the model 1 unit from 0,0,0 into the desired direction but not to the red point nor from the models current position
Hi reset, Your problem is like dreamora says: that you start at the wrong point. You also have some mistakes in the mathematics above. Here is a version that should work. Code (csharp): function Start (){ dist = Vector3.Distance(other.position, transform.position); perim = (2*dist)*Mathf.PI; radcirc = perim/360; // this is allready what you want to get cause you used the real distance and not the distance 1 //radcirc = 5*deg; this line is not necessary. } function Update () { mover();} function mover () { //rad = radcirc* Mathf.Deg2Rad; radcirc is already rad you don't have to convert it other.position = transform.position + Vector3(dist*Mathf.Sin(radcirc),0, dist*Mathf.Cos(radcirc)); } I didn't try it. But this should do now what you expected. By
I actually want the model to start from anywhere - Vector3(0,0,0) is right, it is just a default position for the test.