I have a bunch of entities, each with a Strength
and a Health
component, as well as a physics shape.
I am having trouble figuring out how to make them damage each other however. How can I detect a collision between them, and act accordingly?
I was thinking something like:
class DamageOnTouch : SystemBase
{
protected override void OnUpdate()
{
var otherStrength = new ComponentDataFromEntity<Strength>();
var dt = Time.DeltaTime;
Entities.ForEach((Entity entity, ref Health health, in Collision collision) =>
{
if (otherStrength.Exists(collision.Other))
{
health.Value -= otherStrength[collision.Other].Value * dt;
}
})
.Run();
}
}
So I lower my health with the strength of the other entity when there is a collision.
Is something like this possible? Or what is the way to do this?
I tried finding some examples, but I’m getting confused as there seems to be old ways of doing it, so I thought to just ask what the current way is.