User aim functionality.

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
nikolaiko
Posts: 43
Joined: Mon Aug 04, 2014 8:26 am

User aim functionality.

Post by nikolaiko »

Hi, I just started to work with BEPUPhysics and have one question about it.

I created a CharacterController (it have property - Body it represent physical body of character). So, I need ability to detect then one player got other body in aim. But my aim is not a crosschair it is a something like this :
Image.
So for this kind of check I can't use simple raycast. I suppose I need to add somekind of sensor or something like this in my CharacterController in the facing direction, to detect did we have any other players/bodies in the aim sight. Or there is some other way to implement this feature?

Thanks.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: User aim functionality.

Post by Norbo »

If there are few possible targets relative to the number of objects in the scene, then the fastest approach might be to project the positions or bounding boxes of targets onto the screen of the aiming character. Then, compare the projected position/bounds of the character to the aiming area on the screen.

Presumably, things behind walls should be obscured from detection, so occlusion could be checked by sending a ray or a few rays pointed at different areas of the target. If all test rays hit something before they hit the target, it's occluded.

If there are a lot of potential targets such that projecting them all into screenspace is really heavy, it might be faster to just rely entirely on a large number of ray casts spread over the aiming area.

Note that for all tests which involve a lot of ray casts, a common strategy to improve performance is to only sample a subset of the test rays each frame. This can introduce a slight delay into detection, but it's usually short enough to be acceptable. Choosing good sets of samples each frame can improve detection behavior significantly over naive approaches like pure random or sequential grid searches. For example, if you have a budget of 10 detection rays, spreading them over the sample area with low discrepancy (in space and time) would work better than just casting the next few rays in the 'array' of total samples.

Finally, there's the option of creating a detector object in the shape of the targeting frustum. Unfortunately, since the frustum is probably quite large, this will tend to be much slower than other alternatives. A series of enlarging convex casts could be used to approximate a frustum cast, but for long distances, it is again probably slower than the raycast approach.
nikolaiko
Posts: 43
Joined: Mon Aug 04, 2014 8:26 am

Re: User aim functionality.

Post by nikolaiko »

Ok, thanks for reply.

I think I will try make a multiply raycasts on the aiming area.
Post Reply