- Home /
How to draw a line out which traces the SweepTest ray?
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) )
{
...
}
...
}
Answer by Seth-Bergman · Mar 27, 2013 at 08:22 AM
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...
nope, sweep test x number of raycasts where x = number of vertices in mesh
you could drawray for each vertice using a loop if you wanted to see it.
@sparkzbarca is right of course, to see the precise area affected you would want to do each vertex.. but the question was just regarding the direction..
Yup, you're right, therefore I would like to thank the both of you, for helping and explaining what sweeptest actually does to (:
Well, only primitives are documented as supported by sweeptest (sphere, capsule, and box). A mesh collider won't work.
In addition, I am like 99% sure that box/cube also doesn't work as one would expect.
Answer by sparkzbarca · Mar 27, 2013 at 08:22 AM
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.
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)
Hey, thankyou for the explanation, I now understand what does SweepTest do! (:
Your answer
![](https://koobas.hobune.stream/wayback/20220613095201im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
RayCast Activating A Button 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Unity c# Raycast axis stuck on one axis 0 Answers
cant kill more than one enemy C# 2 Answers