Hello everyone! What are my ways to rotate object depending on the terrain under it in DOTS? So the object will be always perpendicular to the terrain under it?
I have already tried to do this using CollisionWorld.CalculateDistance(), but it seems not to work as it should:
https://www.youtube.com/watch?v=p3G0Ms5Y5SE - here is the video showing how it works in my try. You can see that it is not good at all.
Here is the code I used in this try to do movement and rotation
`public partial struct MovementJob : IJobEntity
{
public float time;
[ReadOnly]public CollisionWorld collisionWorld;
public void Execute(ref LocalTransform transform, in MovementComponent movementComponent)
{
float3 tempDir = movementComponent.target - transform.Position;
tempDir.y = 0;
float3 dir = math.normalize(tempDir);if (math.distancesq(movementComponent.target, transform.Position) < 1f) return; CollisionFilter filter = new CollisionFilter { BelongsTo = ~0u, CollidesWith = 1u << 7, GroupIndex = 0 }; float3 originPointDistance = transform.Position; originPointDistance.y -= 1f; var pointDistanceInput = new PointDistanceInput { Filter = filter, Position = originPointDistance, MaxDistance = 1.5f }; if (collisionWorld.CalculateDistance(pointDistanceInput, out DistanceHit closestHit)) { transform.Position.y = closestHit.Position.y + 1; transform.Rotation = quaternion.LookRotation(transform.Forward(), closestHit.SurfaceNormal); } else { Debug.Log("ERROR: Terrain under unit is not found"); } transform.Position += dir * time * movementComponent.speed; }}`
Also pinned the .unitypackage with that scene if needed