Hello,
I am getting some inconsistent behavior on my stick to platform system. I basically grab the translation “velocity” on the platform entity, and update the translation offset on whatever object sticks to the platform. The problem is, the platform will “collide” with the physics body and push the body sometimes. This happens very inconsistently.
I tried “overriding” the dynamic body’s Local To World position in the EndFixedStepSim buffer, which I thought solved my issue until I noticed a collision still happens sometimes.
Other than this the sticking works perfectly…it is more apparent on vertical movements…like an “elevator”…also becomes more apparent if I step frame by frame in the editor vs just playing.
protected override void OnUpdate()
{
var ecb = buffer.CreateCommandBuffer().AsParallelWriter();
Dependency = Entities
.ForEach((Entity entity, int entityInQueryIndex, ref StickToGround stick, ref Translation trans, in LocalToWorld ltw, in DynamicBuffer<PhysicsHitBuffer> buffer) =>
{
int count = 0;
for (int i = 0; i < buffer.Length; i++)
{
var hit = buffer[i];
if (hit.name != stick.physicsHitName) continue;
count++;
stick.lastStickyGround = hit.hitData.entity;
var tv = GetComponent<TranslationVelocity>(stick.lastStickyGround);
if (!stick.sticking)
{
Debug.Log($"Stick");
stick.sticking = true;
}
trans.Value += tv.velocity;
//setting the translation is NOT GOOD ENOUGH.
//you must set the world position directly in the physics loop
//BEFORE the Transform group so collision detections do not "bump" this entity
ecb.SetComponent(entityInQueryIndex, entity, new LocalToWorld { Value = float4x4.TRS(ltw.Position + tv.velocity, ltw.Rotation, 1) });
}
if (count == 0)
{
if (stick.sticking)
stick.sticking = false;
}
})
.Schedule(Dependency);
buffer.AddJobHandleForProducer(Dependency);
}
I need a way to override the collision positions so the dynamic body’s translation just stays to the relevant position.
EDIT: Currently trying to just do this in the TransformSystem instead…seems to be working so far. Had to rework some of the ways I did my grounded detection.