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) )
	{
		...
	}
	...
}

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.

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! (:

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.

Hey, @Seth Bergman, thanks for the help! (:

@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.