Megafunk / MassSample

My understanding of Unreal Engine 5's experimental ECS plugin with a small sample project.
MIT License
681 stars 112 forks source link

Trace Results on Chaos bodies #68

Open aetherspacemind opened 2 months ago

aetherspacemind commented 2 months ago

Hello. Any way to use a line trace to get the body index? (ie the entity index)? I can use the octree but the Fbox is a little awkward for me.

I tried to set the BodyIndex in BodyInstance so that when I use a line trace I get the body index (ie the entity index) I just get an int that = body count. That doesn't work at all obviously and I have tried a bunch of things, moving the for loop way up and poking and prodding in there.

It was mentioned that the physics here used a similar way the landscape is initialized? I'm assuming the entities are "one thing"? I tried looking for other methods in source but I couldn't put anything together. ISM uses the BodyIndex as Instance index.

Megafunk commented 2 months ago

Hmm... I think the body index is for when you trace against an ISM or a skeletal mesh component's collision to map to instances of ISM instances/bones.

The physics is similar to landscapes in that it makes the new Chaos bodies on-the-spot and by mimicking using the built in Chaos physics initialization path in our own code, rather than just using the build in stuff. I think to map from chaos hit to entity ID you could change the Userdata of the body to be the entity index?

Gholtiy commented 2 months ago

Sorry for my question in this issue, but How i can detect collision between Chaos body and Actor? My entity have PhysicsBody trait and i trying to detect that projectile is hitting the entity, and im stuck on this:(

aetherspacemind commented 2 months ago

Use the Octree for now, its pretty fast but lacks accuracy if the detection box is small.. I have gotten pretty far with adding the bodies to an owning component(plus an owning actor) with the index I wanted in my question.

I can post my solution here, though I am not sure what @Megafunk plans to do with his vision on the physics bodies.

Megafunk commented 2 months ago

I think it's worthwhile to have actual physics collision callbacks, I think https://forums.unrealengine.com/t/chaos-contact-modification/517748 a contact modifier callback might do it? I can try something to see...

Gholtiy commented 2 months ago

Also im trying UChaosEventRelay and its looks like right way, but I have no idea how to get it to work