- Home /
Rays in relation to the Distance to another point
Hey there,
I'm using a camera.ScreenPointToRay(mouse.Input) ray and I want to adjust it according to another point, the hand of an enemy. Basically, I want the end of the ray to always be reachable by the hand/the arm of the enemy. To do this, I'm calculating the length of his arm at the start of the game. Now, my question is: How do I use the length of the arm to figure out where the end of the ray should be? I'm using an IK algorithm and it requires the end point to never be out of reach. I'm having quite a hard time figuring this out here and I'm stuck. Thinking about it, I'll rephrase my question: How do I get a ray to stay on a circle with a radius of the length of an arm? It should be able to stay inside the circle, but never leave it.
Greetings,
Chelmney
I need a drawing or screen shot to understand the question...to see the relationship of the arm to the mouse position. FYI, I found that the ray returned by ScreenPointToRay() starts at the near clip plane of the camera.
Okay, simply put: How do I move the end point back inside the circle when it leaves it like that? I know how to check when it passes the circle now, but I don't know how to check where I need to place it so it's on a line from the center of the circle to the end point but still on the edge of the circle if that makes sense.
I'm still fuzzy. This is the second question today that I've struggled conceptually, so it's probably just me. I'm going to guess and make a suggestion. If you go here you will find a script with a library of 3D functions.
http://wiki.unity3d.com/index.php/3d_$$anonymous$$ath_functions
One of the functions is ProjectPointOnLine(). The 'linePoint' parameter will be your ray.origin. The 'lineVec' parameter will be ray.direction. The 'point' parameter will be the origin of the arm. It will return the closest point on the ray to the origin of the arm. If the point is greater than 'Arm Length' away, it cannot be reached. You can also use that point to calculate the closest point on the circle to the line, therefore moving it back in reach:
pointOnCircle = (closestPoint - circleCenter).normalized * armLength + circleCenter;
Your answer
Follow this Question
Related Questions
Round Slider (Circle shaped slider GUI control) 1 Answer
Lines or curves for a smooth circle in Vectrosity 2 Answers
Optimization (2D) - Box Collider vs Circle Collider 2 Answers
Vectrosity : Adding more anchor and control points 0 Answers
How could i show a color expansion from centre of circle to circumference. 0 Answers