- Home /
Center of spherecast
I am using a spherecast
to check whether the ball is going to collide with another ball. I am using a LineRenderer
(Not exactly I am using Vectrosity
lines, but I guess it's same in this context) to draw the aiming.
Now I need two points to draw the line. The first is obviously the transform.position
of the first ball. The second point I am taking as raycasthit.point
. But it's not actually looking good.
What I want is to calculate the center of the spherecast and draw the line representing the center, so that when the spherecast hit another ball, I can show a circle, taking the center of spherecast(instead of the hitpoint) as the center of the circle.
Is there any way I can get the position of the center? One idea was to do a raycast and spherecast both and project a line on the raycast from the hit normal, but since I am noob in all those vector calculation, I couldn't figure out how to do that.
Thanks for the help.
The center of the spherecast is the spherecast radius.
calculate that in relation to your transform first :
var sphereCenter : Vector3 = transform.forward * spherecastRadius;
then take this away from your hit point
var sphereCenterHit : Vector3 = hit.point - sphereCenter;
this is an untested theory, but if it works for you then I shall convert this to an answer.
Your answer
Follow this Question
Related Questions
Finding a point that is "visible" to two objects 2 Answers
Make bullet launch at center of screen 2 Answers
Using Spherecast to identify objects? 1 Answer
SphereCast misses but RayCast and OverlapSphere don't 1 Answer
Car AI help 0 Answers