Raycasting in entity component system

Started by
1 comment, last by Norman Barrows 7 years, 4 months ago

Hello everyone,

I have been looking into a lot of things about Entity component systems and after thinking how i would create one for a game I stumbled across a couple of questions that i need some help answering.

When it comes to ray casting and collision I can see an easy answer to record collision and letting another system deal with the outcomes like damage or HP buff or whatever, 1 of those solutions being some kind of messaging system that stores the collisions (well the 2 entities ID's) and a second solution could be creating a component with this data. All of this could be recorded in the collision system no problem.

Where i see a problem is where ray casting might be done for things other then collision like say avoidance steering behaviour or maybe guard line of sight. I don't see a way to easily resolve this issues as doing this check in say a steering behaviour system is possible but I don't feel its very efficient.

Another ways I have thought about it is to let systems talk to the collision system, but again I don't know if this is really a good idea.

Do anyone have any ideas on a good way to resolve this problem (and i guess problems like it) or if any of the ways i have suggested are viable.

Cheers for any input given.

Advertisement

You'll have some code somewhere (e.g. a physics library) that knows about physics objects and stores them in some way that is efficient for things like collision and raycasting. It doesn't need to be a "system", though there would probably be a "physics system" that is responsible for keeping things in sync - so that for instance, when a Physics component is added to an entity, a corresponding object is added in the physics library (along with some way/token to associate the two representations). So, basically a system responsible for interfacing between your physics library and your "entity component system" architecture.

Any other systems (or whatever code needs to) could then call into this physics system to perform raycasts and such.

as phil says, raycasts usually test against entity locations. so your raycast would be a method of your location component system, the same way that update_location is a location component method. in the case of a raycast, it acts on the entire list of active components, its doesn't just modify a single component in the list the way update_location might. raycast is a form of list search. in an ECS, the list of location components would be the list to search. so raycast should be a location component method.

so whenever some high level controlling code needs to do a raycast - say LOS check for sneak mode - it calls the location system with a starting location and direction for the cast, and the location system returns what they hit.

note that you can also do raycasts vs geometry, in which case it would be the list of renderable meshes, not the entity locations, that would be used.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

This topic is closed to new replies.

Advertisement