How to draw a line out which traces the SweepTest ray like the one below? I would like to do a SweepTest for diagonal direction (topright), however the angle of the SweepTest direction seems to be off and I would like to find out where exactly is the ray pointing towards. Any kind help would be greatly appreciated!
void Start ()
{
Direction.Set( 1, 0, 0 );
DiagonalDirection = Quaternion.AngleAxis( 45, gameObject.transform.forward ) * Direction;
}
void Update ()
{
...
// Check topright
if( rigidbody.SweepTest( DiagonalDirection, out hit, 10) )
{
...
}
...
}
2 Answers
2
you dont seem to understand what sweep test does.
it’s not a ray
it’s basically
foreach (vertice in object.mesh)
{
ray.origin = vertice;
ray.direction = (in your case) DiagonalDiretion;
physics.raycast(ray);
with the results stored in a list
}
more generally your basically moving the object along a path.
If you want what it’s doing move the object in the direction. Thats the path. Its every vertice in the object moving in that direciton.
you can use Debug.DrawLine or Debug.DrawRay:
Debug.DrawRay(transform.position,DiagonalDirection,Color.green);
should do it, you will need to look in the SCENE view to see the line…
the point is to cast not 1 ray but a ray for every vertice to see if at some point a vertice would run into something (like a wall)
– sparkzbarcaHey, thankyou for the explanation, I now understand what does SweepTest do! (:
– Esterelle