Ray casting collisions
Ray casting collisions
Is there a way to make ray casts ignore entities in a certain collision group?
Re: Ray casting collisions
There are overloads of ray cast functions that accept a filter predicate (Func<BroadPhaseEntry, bool>) which can include any custom filtering logic, including looking at a broad phase entry's collision group.
Re: Ray casting collisions
I'm not quite sure how to do that. I've located the ray cast function that I want, but I'm not sure how to pass in a delegate, or what should be in the function for that matter.
Re: Ray casting collisions
Here's an example using a lambda expression for the delegate:
Any BroadPhaseEntry with a collision group equal to the ignored group will result in that expression evaluating to false.
Another example can be found in the usage of the grabber in the BEPUphysicsDemos StandardDemo.cs.
Code: Select all
Space.RayCast(ray, entry => entry.CollisionRules.Group != ignoredGroup, out result);
Another example can be found in the usage of the grabber in the BEPUphysicsDemos StandardDemo.cs.
Re: Ray casting collisions
Okay, that kinda works. What I'm trying to do is cast a ray from an enemy to a character. The RayCastResult.hitObject is always null until the character is right next to the enemy. Why is the ray not traveling farther? This is my raycast
=
Is it a problem that the destination vector is not normalized? Is there anyway to visually see where the rays are being cast?
=
Code: Select all
space.RayCast(new Ray(enemy.body.Position, destination), 200, entry => entry.CollisionRules.Group != enemyGroup, out result);
Is it a problem that the destination vector is not normalized? Is there anyway to visually see where the rays are being cast?
Re: Ray casting collisions
Okay, that kinda works. What I'm trying to do is cast a ray from an enemy to a character. The RayCastResult.hitObject is always something other than the character until the character is right next to the enemy. Here is my raycast
Would it be a problem that the destination vector isn't normalized?
Code: Select all
space.RayCast(new Ray(enemy.body.Position, destination), 200, entry => entry.CollisionRules.Group != enemyGroup, out result);
Re: Ray casting collisions
The length is in terms of the ray direction length. So if the length of the ray direction is 0.01 and the maximum length is 200, the ray will actually be 2 units long.Is it a problem that the destination vector is not normalized?
Also, the function returns true if it hits anything and false otherwise. Checking this is a better approach than looking at the result, since its contents are technically undefined if the ray cast returns false.
There's nothing special for space ray casts in particular in the BEPUphysicsDrawer, but visualizing a ray is pretty easy. Just draw a line from ray.Position to ray.Position + ray.Direction * maximumLength (or to the hit point, if one exists).Is there anyway to visually see where the rays are being cast?
Re: Ray casting collisions
This still isn't working. I decided to try casting a ray from vector3(0,0,0) toward the character. If the character is directly below (0,0,0) (or very close to) they ray hits. If the character moves away from that spot then it stopped hitting him. I then tried setting they ray to begin from the same Y location as the character and then direct it to the character's X,Z location. (I have a completely flat ground) They ray hits the ground with a T of .069. If the the ray and the character are at the same height shouldn't the ray be perfectly horizontal?
Re: Ray casting collisions
Sorry, I don't have enough information to know exactly what's going on.
Can you recreate a simple version of the problem in a BEPUphysicsDemos demo so that I can take a closer look?
Are you using the last stable version v1.2.0, or are you using the development fork version?
Can you recreate a simple version of the problem in a BEPUphysicsDemos demo so that I can take a closer look?
Are you using the last stable version v1.2.0, or are you using the development fork version?
Re: Ray casting collisions
I got it fixed I wasn't understanding how the vectors and the rays interacted.