Example #1
0
    public void Update()
    {
        if (gPhysics.s.PhysicEnable == false)
        {
            return;
        }
        for (int i = 0; i < allAttractiveItens.Count; i++)
        {
            for (int j = 0; j < allAttractiveItens.Count; j++)
            {
                GravityBehavior currentBehavior = allAttractiveItens[i];
                GravityBehavior nextBehavior    = allAttractiveItens[j];

                if (i == j)
                {
                    continue;
                }

                distanciaEntreCorpos   = nextBehavior.transform.position - currentBehavior.transform.position;
                distanciaEntreCorpos.z = 0;

                if (distanciaEntreCorpos.magnitude <= ((nextBehavior.collider.bounds.size.x + currentBehavior.collider.bounds.size.x) / 2) + 0.01f)
                {
                    continue;
                }

                if (distanciaEntreCorpos.magnitude > 0.0001f)
                {
                    //Lei da gravitaçao universal F = G(m1*m2)/Dis²;
                    float f = (gPhysics.s.ConstanteGravitacional * ((currentBehavior.rigidbody.mass * nextBehavior.rigidbody.mass) / Mathf.Sqrt(distanciaEntreCorpos.magnitude))) * Time.deltaTime;
                    currentBehavior.rigidbody.AddForce(f * distanciaEntreCorpos.normalized);
                }
            }
        }
    }
Example #2
0
        public void AgentsRiseWhenBuried()
        {
            NativeArray <AgentKinematics> agents = new NativeArray <AgentKinematics>(1, Allocator.Persistent);

            agents[0] = new AgentKinematics()
            {
                velocity = new float3(0, 0, 0)
            };

            NativeArray <float3> steering = new NativeArray <float3>(1, Allocator.Persistent);

            steering[0] = new float3(0, 0, 0);

            NativeArray <AgentBehaviors> active = new NativeArray <AgentBehaviors>(1, Allocator.Persistent);

            active[0] = AgentBehaviors.Active;

            NativeArray <VRoxel.Navigation.Block> blocks = new NativeArray <VRoxel.Navigation.Block>(1, Allocator.Persistent);

            VRoxel.Navigation.Block solidBlock = new VRoxel.Navigation.Block();
            solidBlock.solid = true; solidBlock.cost = 1; blocks[0] = solidBlock;

            NativeArray <byte> voxels = new NativeArray <byte>(1, Allocator.Persistent);

            AgentWorld world = new AgentWorld()
            {
                scale    = 1f,
                offset   = float3.zero,
                center   = new float3(0.5f, 0.5f, 0.5f),
                rotation = quaternion.identity,
            };

            GravityBehavior job = new GravityBehavior()
            {
                gravity   = new float3(0, -4f, 0),
                world     = world,
                steering  = steering,
                behaviors = active,
                agents    = agents,
                blocks    = blocks,
                voxels    = voxels,
            };

            job.Schedule(1, 1).Complete();

            Assert.AreEqual(new float3(0, 2, 0), steering[0]);

            agents.Dispose();
            active.Dispose();
            blocks.Dispose();
            voxels.Dispose();
            steering.Dispose();
        }