entity element system – In Unity 2021.3.29(built-in render pipeline, entities 0.51.1-preview.21), what’s the correct means of DOTS based mostly collision detection?

entity element system – In Unity 2021.3.29(built-in render pipeline, entities 0.51.1-preview.21), what’s the correct means of DOTS based mostly collision detection?

[ad_1]

Packages Put in:

Entities: com.unity.entities Model 0.51.1-preview.21
Documentation URL: https://docs.unity3d.com/Packages/[email protected]/handbook/index.html

Physics: com.unity.physics Model 0.51.0-preview.32 – June 15, 2022
Documentation URL: https://docs.unity3d.com/Packages/[email protected]/handbook/index.html

Havok Physics: com.havok.physics Model 0.50.0-preview.24 – March 16, 2022
Documentation URL: https://docs.unity3d.com/Packages/[email protected]/handbook/index.html

Hybrid Renderer: com.unity.rendering.hybrid Model 0.51.1-preview.21 – August 02, 2022
Documentation URL: https://docs.unity3d.com/Packages/[email protected]/handbook/index.html

enter image description here

The entity for which I need to detect collisions for are baby objects in a prefab, as illustrated within the above picture(heartslime_entity).

I’ve hooked up each Physics Form and Physics Physique on every entity, ConvertToEntity.cs(built-in) and a customized authoring script that completes the conversion to an entity and provides element information. For some motive that I don’t know the right way to debug for, these entities, after they’re instantiated, should not correctly colliding with one another. I do not see them colliding bodily nor do they correctly register a CollisionEvent in an carried out ICollisionEventsJob. Right here is my predominant SystemBase script that has a number of duties, in addition to detecting collisions.
VertexUpdater.cs:

utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
utilizing Unity.Entities;
utilizing Unity.Jobs;
utilizing Unity.Collections;
utilizing HerminkasGams.SpriteSquash;
utilizing System.Linq;
utilizing UnityEditor;
utilizing Unity.Burst;
utilizing Unity.Collections.LowLevel.Unsafe;
utilizing System.Runtime.Serialization;
utilizing Unity.VisualScripting;
utilizing System.Safety.Cryptography;
utilizing System;
utilizing Unity.Physics;
utilizing Unity.Physics.Programs;
// utilizing Unity.Physics.Stateful;
utilizing UnityEngine.Rendering;
utilizing Unity.Arithmetic;

public struct MeshDataComponent : IComponentData
{
    public DynamicBuffer<VertexBufferElement> vertices;
}

//[UpdateInGroup(typeof(FixedStepSimulationSystemGroup))]
// [UpdateAfter(typeof(PhysicsInitializeGroup))]
// [UpdateAfter(typeof(PhysicsSimulationGroup))]
//[UpdateInGroup(typeof(FixedStepSimulationSystemGroup))]
//[UpdateAfter(typeof(StatefulTriggerEventBufferSystem))]
[UpdateInGroup(typeof(FixedStepSimulationSystemGroup)), UpdateBefore(typeof(EndFramePhysicsSystem)), UpdateAfter(typeof(StepPhysicsWorld))]
public partial class VertexUpdater : SystemBase
{
    public GameObject ObjectManager;
    public ObjectManagerController objectManagerController;
    non-public BuildPhysicsWorld _buildPhysicsWorld;
    non-public StepPhysicsWorld _stepPhysicsWorld;
    non-public EndFramePhysicsSystem endFramePhysicsSystem;
    non-public EndSimulationEntityCommandBufferSystem endSimulationEntityCommandBufferSystem;

    [HideInInspector] public Checklist<SpriteMeshModifier> spriteMeshModifiers = new Checklist<SpriteMeshModifier>();
    // [HideInInspector] public Checklist<Vertex> vertices = new Checklist<Vertex>();  // Checklist of vertices; every component of this variable is what I have to make magnetic
    bool merged = false;

    non-public struct VertexCopy {
        public Vector3 _currentPos;
        public Vector3 _initialPos;
        public Vector3 _revertingPos;
        public int _metaballEdgePointCount;

        //_parentSpriteMeshModifier variables:
        public Vector3 _parentSpriteMeshModifierPosition;
        public Quaternion _parentSpriteMeshModifierRotation;
        public Vector3 _parentSpriteMeshModifierLocalscale;

        [HideInInspector]public int _index;
        [HideInInspector]public Vector3 _closestMagnetPoint;
        [HideInInspector] public float _minDistanceToInitialpos;
    
        public VertexCopy(Vector3 pos, Vector3 initialPos, int index, int metaballEdgePointCount, Vector3 parentSpriteMeshModifierPosition, Quaternion parentSpriteMeshModifierRotation, Vector3 parentSpriteMeshModifierLocalscale, Vector3 closestMagnetPoint) {
            _currentPos = pos;
            _initialPos = initialPos;
            _revertingPos = pos;
            _index = index;
            _metaballEdgePointCount = metaballEdgePointCount;
            //_parentSpriteMeshModifierPosition variables
            _parentSpriteMeshModifierPosition = parentSpriteMeshModifierPosition;
            _parentSpriteMeshModifierRotation = parentSpriteMeshModifierRotation;
            _parentSpriteMeshModifierLocalscale = parentSpriteMeshModifierLocalscale;
            _closestMagnetPoint = closestMagnetPoint;
            _minDistanceToInitialpos = 0;
        }

        public (Vector3, float) FindNearestMagnetPoint(NativeArray<Vector3> metaballVertexPositionArray) {
            float minDistanceUnaltered = 99999;
            // float minDistanceToInitialposUnaltered = 0;
            Vector3 scpInitial = _parentSpriteMeshModifierRotation * _initialPos;
            Vector3 pointInitial = new Vector3(scpInitial.x * _parentSpriteMeshModifierLocalscale.x, scpInitial.y * _parentSpriteMeshModifierLocalscale.y, scpInitial.z * _parentSpriteMeshModifierLocalscale.z) + _parentSpriteMeshModifierPosition;
            //Compute the closest metaball edge magnet level by iterating by way of them if metaballEdgePointVertexGOs isn't empty
            if (_metaballEdgePointCount > 0) {
                int index = 0;
                Vector3 scp = _parentSpriteMeshModifierRotation * _currentPos;
                Vector3 level = new Vector3(scp.x * _parentSpriteMeshModifierLocalscale.x, scp.y * _parentSpriteMeshModifierLocalscale.y, scp.z * _parentSpriteMeshModifierLocalscale.z) + _parentSpriteMeshModifierPosition;
                
                float minDistance = 99999;

                //Will iterate by way of metaballEdgePointVertexGOs to search out closest
                //Vector3 scpMagnet = new Vector3(0,0,0);
                for (int i = 0; i < _metaballEdgePointCount; i++)
                {   
                    float dis = Vector2.Distance(level, metaballVertexPositionArray[i]);
                    if (dis < minDistance)
                    {
                        index = i;
                        minDistance = dis;
                    }
                }
                _minDistanceToInitialpos = Vector2.Distance(level, pointInitial);
                
                //Invert metaballVertexPositionArray[index] again to vertex coordinates
                Vector3 vec1 = metaballVertexPositionArray[index] - _parentSpriteMeshModifierPosition;
                Vector3 vec2 = _parentSpriteMeshModifierLocalscale;
                Vector3 outcome = new Vector3(vec1.x / vec2.x, vec1.y / vec2.y, vec1.z / vec2.z);
                Vector3 scpLocal = Quaternion.Inverse(_parentSpriteMeshModifierRotation) * (outcome);
                return (scpLocal, minDistance);
            }
            return (new Vector3(0,0,-1), minDistanceUnaltered);
        }
    }

    [BurstCompile]
    non-public struct ComputeJob : IJobFor {
        [NativeDisableParallelForRestriction] public NativeArray<VertexCopy> vertexCopyArray;
        //[NativeDisableParallelForRestriction] public NativeArray<Vector3> updatePositionsArray;
        // Tips that could the beginning of the mesh.vertices array
        // [NativeDisableParallelForRestriction][NativeDisableUnsafePtrRestriction] public Vector3* meshVertices;
        // [NativeDisableParallelForRestriction][NativeDisableUnsafePtrRestriction] public Vector3* Vertices;
        [ReadOnly] public NativeArray<Vector3> metaballVertexPositionArray;
        
        public unsafe void Execute(int index) {
            VertexCopy vertexCopy = vertexCopyArray[index];
            float minDistance = 9999;
            (vertexCopy._closestMagnetPoint, minDistance) = vertexCopy.FindNearestMagnetPoint(metaballVertexPositionArray);
            //If closest distance is lower than threshold
            if (minDistance < 0.8f) {
                //vertexCopy._currentPos = vertexCopy._closestMagnetPoint;
                Vector3 updatePosition = Vector3.Lerp(vertexCopy._closestMagnetPoint, vertexCopy._initialPos, (vertexCopy._minDistanceToInitialpos + minDistance * (1 - vertexCopy._minDistanceToInitialpos / 0.8f)) / (1.0f + minDistance * (1 - vertexCopy._minDistanceToInitialpos / 0.8f)));
                //updatePositionsArray[index] = updatePosition;
                vertexCopy._currentPos = updatePosition;
                vertexCopyArray[index] = vertexCopy;
                //UnsafeUtility.WriteArrayElement(meshVertices, vertCount + n, vertexCopyArray);
            }
            else {
                //Rewrite to reset place
                vertexCopy._currentPos = vertexCopy._initialPos;
                //updatePositionsArray[index] = vertexCopy._initialPos;
                vertexCopyArray[index] = vertexCopy;
            }
        }
    }

    // [BurstCompile]
    public struct CollisionEventJob : ICollisionEventsJob
    {
        public ComponentDataFromEntity<IsStaticComponent> isStatic;
        public ComponentDataFromEntity<SizeComponent> measurement;
        public ComponentDataFromEntity<MarkForDelete> markForDelete;
 
        public void Execute(CollisionEvent evt)
        {
            Debug.Log("Fuck");
            // Guarantee each entities have the IsStaticComponent.
            if (!isStatic.HasComponent(evt.EntityA) || !isStatic.HasComponent(evt.EntityB))
            {
                return; // Not less than one of many entities does not have the required element, so we skip.
            }
            Entity staticEntity;
            Entity dynamicEntity;

            IsStaticComponent entityAStatic = isStatic[evt.EntityA];
            IsStaticComponent entityBStatic = isStatic[evt.EntityB];

            // Decide which entity is static and which is dynamic.
            if(entityAStatic.isStatic && !entityBStatic.isStatic)
            {
                staticEntity = evt.EntityA;
                dynamicEntity = evt.EntityB;
            }
            else if(!entityAStatic.isStatic && entityBStatic.isStatic)
            {
                staticEntity = evt.EntityB;
                dynamicEntity = evt.EntityA;
            }
            else
            {
                // Both each are static or each are dynamic.
                // Randomly choose one to be the static entity and the opposite to be the dynamic entity.
                bool randomDecision = UnityEngine.Random.worth > 0.5f;
                if (randomDecision)
                {
                    staticEntity = evt.EntityA;
                    dynamicEntity = evt.EntityB;
                }
                else
                {
                    staticEntity = evt.EntityB;
                    dynamicEntity = evt.EntityA;
                }
            }

            // Modify the scale of the static entity by including the scale of the dynamic entity.
            SizeComponent staticSize = measurement[staticEntity];
            SizeComponent dynamicSize = measurement[dynamicEntity];

            float currentArea = staticSize.width * staticSize.top;
            float updatedArea = currentArea + dynamicSize.width * dynamicSize.top;
            staticSize.width = (updatedArea/currentArea)*staticSize.width;
            staticSize.top = (updatedArea/currentArea)*staticSize.top;

            measurement[staticEntity] = staticSize;

            // Mark the dynamic entity for deletion.
            //markForDelete[dynamicEntity] = new MarkForDelete { markForDelete = true };
        }
    }

    protected override void OnStartRunning()
    {
        ObjectManager = GameObject.Discover("ObjectManager");
        objectManagerController = ObjectManager.GetComponent<ObjectManagerController>();
        // GameObject.Discover("SpriteMeshModifier");
        // EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
        // // Create an Entity "archetype" that may have MyComponent
        // EntityArchetype spriteMeshModifierArchetype = entityManager.CreateArchetype(typeof(SpriteMeshModifier));
        // // Create an entity with that archetype
        // Entity spriteMeshModifierEntity = entityManager.CreateEntity(spriteMeshModifierArchetype);

        Checklist<GameObject> waterslimesDisplay = objectManagerController.colorSlimesDisplayGlobal;
        foreach (GameObject waterslimeDisplay in waterslimesDisplay) {
            spriteMeshModifiers.Add(waterslimeDisplay.GetComponent<SpriteMeshModifier>());
        }
        // Get references to the required physics programs
        _buildPhysicsWorld = World.GetOrCreateSystem<BuildPhysicsWorld>();
        _stepPhysicsWorld = World.GetOrCreateSystem<StepPhysicsWorld>();
        endSimulationEntityCommandBufferSystem = World.GetOrCreateSystem<EndSimulationEntityCommandBufferSystem>();
        // Register the physics system as read-write or read-only based mostly in your necessities
        this.RegisterPhysicsRuntimeSystemReadWrite();
        base.OnStartRunning();
    }

    protected override void OnUpdate()
    {
        spriteMeshModifiers = new Checklist<SpriteMeshModifier>();
        Checklist<GameObject> waterslimesDisplay = objectManagerController.colorSlimesDisplayGlobal;
        foreach (GameObject waterslimeDisplay in waterslimesDisplay) {
            spriteMeshModifiers.Add(waterslimeDisplay.GetComponent<SpriteMeshModifier>());
        }
        consolidateGameObjectToPos2D(Vector3.zero, 0.6f);
        //revertGameObjectToInitialpos2D(0.6f);
        CallJobs();
        //QueryVelocitiesAndUpdateStaticComponents();

        // Collision Job
        CollisionEventJob collisionJob = new CollisionEventJob
        {
            isStatic = GetComponentDataFromEntity<IsStaticComponent>(),
            measurement = GetComponentDataFromEntity<SizeComponent>(),
            markForDelete = GetComponentDataFromEntity<MarkForDelete>()
        };
        // Schedule the job with the dependencies of the StepPhysicsWorld system
        JobHandle jobHandle = collisionJob.Schedule(_stepPhysicsWorld.Simulation, Dependency);

        //Code that's crucial for some motive
        endSimulationEntityCommandBufferSystem.AddJobHandleForProducer(Dependency);

        // Be certain to finish the job earlier than the tip of the body
        // This line is critical if you might want to learn the job information in the identical body
        jobHandle.Full();

        // Replace the Dependency deal with
        Dependency = jobHandle;

        //Replace the precise MonoBehavior sport objects based mostly on circumstances of the entities
        //UpdateMonoBehaviorGameObjectsAfterCollision();
        //throw new System.NotImplementedException();
    }

    non-public unsafe void CallJobs() {
        foreach (SpriteMeshModifier spriteMeshModifier in spriteMeshModifiers) {
            //&& spriteMeshModifier._isRegenerated
            if(spriteMeshModifier.vertices.Depend > 0 && spriteMeshModifier._isSerializedRegenerated && spriteMeshModifier.objectManagerController.metaballEdgePointVertices.Depend > 0) {
                NativeArray<VertexCopy> vertexCopies = new NativeArray<VertexCopy>(spriteMeshModifier.vertices.Depend, Allocator.TempJob);
                //NativeArray<Vector3> updatePositions = new NativeArray<Vector3>(spriteMeshModifier.vertices.Depend, Allocator.TempJob);
                NativeArray<Vector3> metaballVertexPositions = new NativeArray<Vector3>(spriteMeshModifier.objectManagerController.metaballEdgePointVertices.Depend, Allocator.TempJob);
                
                CopyThingsTo(ref vertexCopies, ref metaballVertexPositions, spriteMeshModifier);
                // Do heavy computation in a job
                ComputeJob job = new ComputeJob() {
                    vertexCopyArray = vertexCopies,
                    //updatePositionsArray = updatePositions,
                    metaballVertexPositionArray = metaballVertexPositions,
                };
                job.ScheduleParallel(vertexCopies.Size, 64, default).Full();
                //spriteMeshModifier.GetComponent<MeshFilter>().sharedMesh.vertices = mesh.vertices;
                //Dispose out of date NativeArrays
                // updatePositions.Dispose();
                metaballVertexPositions.Dispose();

                //Replace SpriteMeshmodifier.vertices' currentPos
                for (int i = 0; i < spriteMeshModifier.vertices.Depend; i++) {
                    spriteMeshModifier.vertices[i]._closestMagnetPoint = vertexCopies[i]._closestMagnetPoint;
                    spriteMeshModifier.vertices[i].currentPos = vertexCopies[i]._currentPos;
                }
                spriteMeshModifier.UpdateMesh();

                // Remember to dispose
                vertexCopies.Dispose();
            }
            else if(spriteMeshModifier.vertices.Depend > 0 && spriteMeshModifier._isSerializedRegenerated && spriteMeshModifier.objectManagerController.metaballEdgePointVertices.Depend <= 0) {
                // Debug.Log("metaballEdgePointVertices.Depend: " + spriteMeshModifier.objectManagerController.metaballEdgePointVertices.Depend);
                //Reset vertices for every sport object
                spriteMeshModifier.Reset();
            }
        }
    }

    //ref NativeArray<Vector3> updatePositionsArray, 
    non-public void CopyThingsTo(ref NativeArray<VertexCopy> copiesArray, ref NativeArray<Vector3> metaballVertexPositionsArray, SpriteMeshModifier spriteMeshModifier) {
        for (int i = 0; i < spriteMeshModifier.vertices.Depend; i++) {
            Vertex vertex = spriteMeshModifier.vertices[i];
            copiesArray[i] = new VertexCopy(vertex.currentPos, vertex.initialPos, i, vertex._objectManagerController.metaballEdgePointVertices.Depend, vertex._parentSpriteMeshModifier.rework.mother or father.gameObject.rework.place, vertex._parentSpriteMeshModifier.gameObject.rework.rotation, vertex._parentSpriteMeshModifier.gameObject.rework.localScale, vertex._closestMagnetPoint);
            //updatePositionsArray[i] = new Vector3(vertex.currentPos.x, vertex.currentPos.y, vertex.currentPos.z);
        }
        for (int i = 0; i < spriteMeshModifier.objectManagerController.metaballEdgePointVertices.Depend; i++) {
            Vector3 metaballEdgePointVertex = spriteMeshModifier.objectManagerController.metaballEdgePointVertices[i];
            metaballVertexPositionsArray[i] = metaballEdgePointVertex;
        }
    }

    // non-public void AssignComputedValues(in NativeArray<VertexCopy> copiesArray, SpriteMeshModifier spriteMeshModifier) {
    //     for (int i = 0; i < spriteMeshModifier.vertices.Depend; ++i) {
    //         spriteMeshModifier.vertices[i]._closestMagnetPoint = copiesArray[i]._closestMagnetPoint;
    //     }
    // }

    non-public void UpdatePositions(NativeArray<VertexCopy> copiesArray, SpriteMeshModifier spriteMeshModifier) {
        spriteMeshModifier.UpdateMesh();
    }
    non-public void consolidateGameObjectToPos2D(Vector3 pos, float pace) {
        if(!merged) {
            merged = true;
            foreach (SpriteMeshModifier spriteMeshModifier in spriteMeshModifiers) {
                if(spriteMeshModifier.rework.mother or father.gameObject.rework.place != pos) {
                    //Compute GCD Vector3 between spriteMeshModifier.rework.mother or father.gameObject.rework.place and Vector3.zero
                    Vector3 deltaVector = pos - spriteMeshModifier.rework.mother or father.gameObject.rework.place;
                    //int gcd = binaryGCD(Math.Abs((int)deltaVector.x), Math.Abs((int)deltaVector.y));
                    
                    deltaVector = new Vector3(pace * (deltaVector.x / System.Math.Abs(deltaVector.x)), pace * (deltaVector.y / System.Math.Abs(deltaVector.x)), deltaVector.z);
                    spriteMeshModifier.rework.mother or father.gameObject.rework.place += deltaVector;
                    
                    if((spriteMeshModifier.rework.mother or father.gameObject.rework.place.x > pos.x + 0.01f) || (spriteMeshModifier.rework.mother or father.gameObject.rework.place.x < pos.x - 0.01f) || (spriteMeshModifier.rework.mother or father.gameObject.rework.place.y > pos.y + 0.01f) || (spriteMeshModifier.rework.mother or father.gameObject.rework.place.y < pos.y - 0.01f)) {
                        merged = false;
                    }
                }
            }
        }
    }
    non-public void revertGameObjectToInitialpos2D(float pace) {
        if(merged) {
            merged = false;
            foreach (SpriteMeshModifier spriteMeshModifier in spriteMeshModifiers) {
                Vector3 initialPos = spriteMeshModifier.colorslimeMainInitialPos;
                if(spriteMeshModifier.rework.mother or father.gameObject.rework.place != initialPos) {
                    //Compute GCD Vector3 between spriteMeshModifier.rework.mother or father.gameObject.rework.place and Vector3.zero
                    Vector3 deltaVector = initialPos - spriteMeshModifier.rework.mother or father.gameObject.rework.place;
                    //int gcd = binaryGCD(Math.Abs((int)deltaVector.x), Math.Abs((int)deltaVector.y));
                    
                    deltaVector = new Vector3(pace * (deltaVector.x / System.Math.Abs(deltaVector.x)), pace * (deltaVector.y / System.Math.Abs(deltaVector.x)), deltaVector.z);
                    spriteMeshModifier.rework.mother or father.gameObject.rework.place += deltaVector;
                    
                    if((spriteMeshModifier.rework.mother or father.gameObject.rework.place.x > initialPos.x + 0.001f) || (spriteMeshModifier.rework.mother or father.gameObject.rework.place.x < initialPos.x - 0.001f) || (spriteMeshModifier.rework.mother or father.gameObject.rework.place.y > initialPos.y + 0.001f) || (spriteMeshModifier.rework.mother or father.gameObject.rework.place.y < initialPos.y - 0.001f)) {
                        merged = true;
                    }
                }
            }
        }
    }
    non-public void QueryVelocitiesAndUpdateStaticComponents() {
        Entities.WithAll<IsStaticComponent>().ForEach(
        (ref PhysicsVelocity velocity, ref IsStaticComponent isStatic) =>
        {
            isStatic.isStatic = math.size(velocity.Linear) < 0.0001f; 
        }).Run();
    }
    non-public void UpdateMonoBehaviorGameObjectsAfterCollision() {
        EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
        foreach (SpriteMeshModifier spriteMeshModifier in spriteMeshModifiers) {
            GameObject gameObjectMain = spriteMeshModifier.rework.mother or father.gameObject;
            GameObject gameObjectDisplay = spriteMeshModifier.gameObject;
            Entity entity = gameObjectMain.GetComponent<HeartSlimeMainController>().entityWrapper.GetComponent<SlimeAuthoring>().thisEntity;
            // Examine if entity exists (additional warning)
            if (!entityManager.Exists(entity))
                proceed;
            // Examine if entity has the MarkForDelete element and if it is set to true
            if (entityManager.HasComponent<MarkForDelete>(entity)) 
            {
                MarkForDelete markForDelete = entityManager.GetComponentData<MarkForDelete>(entity);
                if (markForDelete.markForDelete) 
                {
                    // Delete the GameObject and proceed to the subsequent iteration
                    gameObjectMain.GetComponent<HeartSlimeMainController>().DestroyGameObject();
                    proceed;
                }
            }
            // If not deleted, modify the scale based mostly on the SizeComponent
            if (entityManager.HasComponent<SizeComponent>(entity)) 
            {
                SizeComponent sizeComponent = entityManager.GetComponentData<SizeComponent>(entity);
                MeshRenderer meshRenderer = gameObjectDisplay.GetComponent<MeshRenderer>();
                float previousWidth = meshRenderer.bounds.measurement.x;
                float previousHeight = meshRenderer.bounds.measurement.y;
                float updatedWidth = sizeComponent.width;
                float updatedHeight = sizeComponent.top;
                float widthScaleFactor = updatedWidth / previousWidth;
                float heightScaleFactor = updatedHeight / previousHeight;

                // Assuming you need to modify the native scale of the gameObject, based mostly on sizeComponent.measurement
                Vector3 previousScale = spriteMeshModifier.gameObject.rework.localScale;
                spriteMeshModifier.gameObject.rework.localScale = new Vector3(previousScale.x * widthScaleFactor, previousScale.y * heightScaleFactor, previousScale.z);
            }
        }
    }
    non-public int binaryGCD(int u, int v) {
        if (u == 0) return v;
        if (v == 0) return u;

        int shift;
        // Compute the best energy of two dividing each u and v
        for (shift = 0; ((u | v) & 1) == 0; ++shift) {
            u >>= 1;
            v >>= 1;
        }

        whereas ((u & 1) == 0) u >>= 1;

        // From right here on, u is at all times odd.
        do {
            // Take away all components of two in v since they don't seem to be frequent
            whereas ((v & 1) == 0)  v >>= 1;

            // Now u and v are each odd. Swap if crucial so u <= v, then set v = v - u (which is even).
            if (u > v) {
                int temp = v; 
                v = u; 
                u = temp; // Swap u and v.
            }
        
            v = v - u; // Right here v >= u.
        } whereas (v != 0);

        // Restore frequent components of two.
        return u << shift;
    }
}

Right here is the customized authoring script:
SlimeAuthoring.cs:

utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
utilizing Unity.Entities;

public class SlimeAuthoring : MonoBehaviour, IConvertGameObjectToEntity
{
    public float velocity;
    public Entity thisEntity;
    public GameObject targetSizeObject;

    public void SetEntity(Entity entity)
    {
        thisEntity = entity;
    }

    public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    {
        SetEntity(entity);
        dstManager.AddComponentData(entity, new IsStaticComponent { isStatic = true });

        // Extract measurement
        if(targetSizeObject != null)
        {
            MeshRenderer renderer = targetSizeObject.GetComponent<MeshRenderer>();
            if(renderer != null)
            {
                Vector3 measurement = renderer.bounds.measurement; // this will get the scale of the mesh's bounding field
                dstManager.AddComponentData(entity, new SizeComponent { 
                    width = measurement.x,
                    top = measurement.y 
                }); // assuming SizeComponent takes a float for magnitude
            }
        }
    }
}
public struct IsStaticComponent : IComponentData
{
    public bool isStatic;
}

public struct SizeComponent : IComponentData
{
    public float width;
    public float top;
}

public struct MarkForDelete : IComponentData
{
    public bool markForDelete;
}

For my functions, I can not use URP, HDRP, or SRP, as a result of there’s a crucial script some other place within the challenge that’s depending on the conduct of the built-in render pipeline. From what I’ve researched to date and what others state, the render pipeline mustn’t matter in terms of DOTS collision detection. So I assume there’s a crucial step lacking from what I’ve carried out to date, or one thing incorrect that’s inflicting the entities to not correctly collide with one another nor elevate collision occasions. Please assist me debug what this challenge is.

[ad_2]

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply