コード例 #1
0
    private void ShootBox(sfloat mass, float3 size, float3 startingPos, float3 startingVelocity)
    {
        UnityS.Physics.Material material = UnityS.Physics.Material.Default;
        material.Friction = (sfloat)0.25f;

        PhysicsParams physicsParams = PhysicsParams.Default;

        physicsParams.isDynamic = true;
        physicsParams.startingLinearVelocity = startingVelocity;
        physicsParams.mass = mass;

        GameController.Instance.CreateBox(startingPos,
                                          size, quaternion.identity, material, physicsParams);
    }
コード例 #2
0
    private void ShootBall(sfloat mass, sfloat radius, float3 startingPos, float3 startingVelocity)
    {
        UnityS.Physics.Material material = UnityS.Physics.Material.Default;
        material.Friction    = (sfloat)0.25f;
        material.Restitution = (sfloat)0.25f;

        PhysicsParams physicsParams = PhysicsParams.Default;

        physicsParams.isDynamic = true;
        physicsParams.startingLinearVelocity = startingVelocity;
        physicsParams.mass           = mass;
        physicsParams.angularDamping = (sfloat)0.9f;

        GameController.Instance.CreateBall(startingPos, radius, material, physicsParams);
    }
コード例 #3
0
    protected override void OnCreate()
    {
        base.OnCreate();
        Instance = this;
        UnityEngine.Physics.autoSimulation = false;

        matPropBlock = new MaterialPropertyBlock();

        // setup physics parameters
        World.GetOrCreateSystem <FixedStepSimulationSystemGroup>().Timestep = (float)(sfloat.One / (sfloat)60.0f);
        Entity      physicsStep       = EntityManager.CreateEntity(typeof(PhysicsStep));
        PhysicsStep physicsStepParams = PhysicsStep.Default;

        physicsStepParams.SolverStabilizationHeuristicSettings = new Solver.StabilizationHeuristicSettings
        {
            EnableSolverStabilization = true,
            EnableFrictionVelocities  = true,
            InertiaScalingFactor      = (sfloat)0.0f,
            VelocityClippingFactor    = (sfloat)1.0f
        };

        physicsStepParams.SolverIterationCount = 3;
        physicsStepParams.MultiThreaded        = 1;
        physicsStepParams.Gravity = new float3(sfloat.Zero, (sfloat)(-60.0f), sfloat.Zero);
        EntityManager.SetComponentData(physicsStep, physicsStepParams);

        UnityS.Physics.Material material = UnityS.Physics.Material.Default;
        material.Friction = sfloat.One;

        PhysicsParams physicsParamsStatic = PhysicsParams.Default;

        physicsParamsStatic.isDynamic = false;

        PhysicsParams physicsParamsDynamic = PhysicsParams.Default;

        physicsParamsDynamic.isDynamic = true;

        CreateBox(new float3(sfloat.Zero, sfloat.Zero, sfloat.Zero), new float3((sfloat)500.0f, (sfloat)2.0f, (sfloat)500.0f), quaternion.identity, material, physicsParamsStatic);

        sfloat radius  = (sfloat)10.0f;
        int    count   = 7;
        sfloat sfcount = (sfloat)count;

        int layers = 4;

        sfloat size          = (sfloat)6.0f;
        sfloat anglePerLayer = (sfloat)0.25f;

        // set up stacked boxes
        for (int l = 0; l < layers; l++)
        {
            sfloat offsetY     = sfloat.One + ((sfloat)l + (sfloat)0.5f) * size;
            sfloat angleOffset = anglePerLayer * (sfloat)l;

            for (int i = 0; i < count; i++)
            {
                sfloat t = (sfloat)i / sfcount * math.PI * (sfloat)2.0f + angleOffset;
                math.sincos(t, out sfloat sin, out sfloat cos);
                float3 pos = new float3(radius * cos, offsetY, radius * sin);

                CreateBox(pos, new float3(size, size, size),
                          quaternion.AxisAngle(new float3(sfloat.Zero, sfloat.One, sfloat.Zero), -t),
                          material, physicsParamsDynamic);
            }
        }
    }