Comments and answers for "Math Question : How to Get a Point on a Ray which is EXACTLY 5 units away from Vector3.Zero?"
http://answers.unity.com/questions/313702/math-question-how-to-get-a-point-on-a-ray-which-is.html
The latest comments and answers for the question "Math Question : How to Get a Point on a Ray which is EXACTLY 5 units away from Vector3.Zero?"Comment by Trithilon on Trithilon's answer
http://answers.unity.com/comments/356746/view.html
Naah... I want to avoid such work arounds and keep everything controlled via script. In anycase... answers I got were good enough for me. :)Fri, 30 Nov 2012 09:48:40 GMTTrithilonAnswer by FWCorey
http://answers.unity.com/answers/356668/view.html
Make the sphere a child object of a child object of the planet at exactly 5 units away along the z axis and just put a LookAt script on the sphere's parent to look at a dummy object that is always synced to the mouse pointer. That should give you the effect you are looking for with the least effort.Fri, 30 Nov 2012 06:42:33 GMTFWCoreyComment by Trithilon on Trithilon's answer
http://answers.unity.com/comments/314611/view.html
Hey, Thanks it works now. :)
Just that I need it to be exactly under my finger now.
Will try to figure that out. :)Fri, 07 Sep 2012 11:10:22 GMTTrithilonComment by Cripple on Cripple's answer
http://answers.unity.com/comments/314185/view.html
Vector3 point = centerOfSphere + ray.direction * -1 * 5.0f;
You can multiply a direction by -1 to get its opposite.Thu, 06 Sep 2012 16:18:38 GMTCrippleComment by Trithilon on Trithilon's answer
http://answers.unity.com/comments/314100/view.html
But my Ray starts from the Camera.
And I need to get the point in the world on the ray which would essentially be 5 units from (0,0,0). That is the issue...Thu, 06 Sep 2012 13:46:51 GMTTrithilonComment by Eric5h5 on Eric5h5's answer
http://answers.unity.com/comments/314095/view.html
GetPoint takes a float, which is the distance. So if you use 5.0, assuming the origin of the ray is Vector3.zero, then the distance from there is 5.0.Thu, 06 Sep 2012 13:36:37 GMTEric5h5Comment by Trithilon on Trithilon's answer
http://answers.unity.com/comments/313895/view.html
You want me to run a for loop using ray.Getpoint(forloopcounter) ? And approximate which one was the closest? I will be limited with the resolution I can get.
Check my post - I have add a webplayer build to show you what I have and described what i want.Thu, 06 Sep 2012 07:10:21 GMTTrithilonComment by Trithilon on Trithilon's answer
http://answers.unity.com/comments/313892/view.html
Yes.... but GetPoint only gives me a point from the Ray. But It needs a distance. I don't know at what distance will I make sure that the Point it GET will be exactly 5.0f from Vector3.zero.Thu, 06 Sep 2012 07:08:35 GMTTrithilonComment by Trithilon on Trithilon's answer
http://answers.unity.com/comments/313886/view.html
If I got you correctly, I have already achieved this. But its on a 2D plane and always keeps the distance snapped to 5.0f.
I want to snap it along the surface of the planet so that it will start hovering above the sphere when I try to pull it into the sphere. (As if it was linked to the center of the sphere with a fixed joint that maintains a distance of 5 units)Thu, 06 Sep 2012 07:02:19 GMTTrithilonComment by Trithilon on Trithilon's answer
http://answers.unity.com/comments/313885/view.html
Hello,
I tried but it wont work. It essentially kind of ends up projecting it on a plane. I wish to - you could say - project it on the surface of a virtual sphere.
You should be able to see half of what I am trying to achieve in the webplayer demo I posted. It never comes closer or further away from the sphere. I want it to Vertically snap and travel along the surfacenormal (without using raycasts or invisible spehere colliders) when I try to drag it closer to the Planet.Thu, 06 Sep 2012 06:58:45 GMTTrithilonAnswer by Foam
http://answers.unity.com/answers/313760/view.html
You should note that EXACTLY 5 units is a tricky thing when using floats and math operations.
If you're using LARGER THAN that's polled frequently enough you should be fine but just using 1 check can be fatal due to rounding errors.Wed, 05 Sep 2012 22:41:29 GMTFoamAnswer by Eric5h5
http://answers.unity.com/answers/313751/view.html
Use [Ray.GetPoint][1].
[1]: http://docs.unity3d.com/Documentation/ScriptReference/Ray.GetPoint.htmlWed, 05 Sep 2012 22:22:53 GMTEric5h5Answer by Piflik
http://answers.unity.com/answers/313721/view.html
You need the point on the ray, that is closest to your origin. Measure the distance and then you can calculate the two points (**it's always two**) on the ray that are 5 units from the origin (you get the distance between the closest point and your wanted point by way of the theorem of Pythagoras). But I am not sure this will help you at all...
What I would do, is calculate the distance between the sphere and the planet, and if it is bigger or smaller than a certain threshold, you set it to be that exact threshold.
Example:
var maxDist : int;
var minDist = int;
private var direction : Vector3;
function Update() {
direction = sphere.position - planet.position;
if(direction.magnitude > maxDist)
sphere.position = planet.position + direction.normalized * maxDist;
if(direction.magnitude < minDist)
sphere.position = planet.position +direction.normalized * minDist;
}Wed, 05 Sep 2012 21:09:55 GMTPiflikAnswer by Cripple
http://answers.unity.com/answers/313716/view.html
Hi, you should read some doc about vectors & stuff.
http://docs.unity3d.com/Documentation/Manual/VectorCookbook.html
Here is what you are looking for :
Vector3 point = centerOfSphere + ray.direction * 5.0f;
You add to the origin point the vector which will give you your final point. You want to follow the ray so you get its direction (it is normalized, so its magnitude is 1) and you multiply it by the distance you want to travel (here 5 units).Wed, 05 Sep 2012 21:05:50 GMTCripple