コード例 #1
0
    public Vector3 CalculatePunishingForce(SimpleSphereCollider otherCollider)
    {
        var deltaVector = otherCollider.transform.position - transform.position;
        var maxDistance = otherCollider.radius + radius;

        if (deltaVector.x > maxDistance || deltaVector.y > maxDistance || deltaVector.z > maxDistance)
        {
            return(Vector3.zero);
        }

        var intersectionAmount = deltaVector.magnitude;

        if (intersectionAmount > maxDistance)
        {
            return(Vector3.zero);
        }

        if (intersectionAmount == 0f)
        {
            intersectionAmount = Random.Range(-Time.deltaTime, Time.deltaTime);
        }

        var intersectionDirection = deltaVector / intersectionAmount;

        return(intersectionDirection * (maxDistance - intersectionAmount));
    }
コード例 #2
0
    public Vector3 CalculatePunishingForce( SimpleSphereCollider otherCollider )
    {
        var deltaVector = otherCollider.transform.position - transform.position;
        var maxDistance = otherCollider.radius + radius;

        if ( deltaVector.x > maxDistance || deltaVector.y > maxDistance || deltaVector.z > maxDistance ) {

            return Vector3.zero;
        }

        var intersectionAmount = deltaVector.magnitude;

        if ( intersectionAmount > maxDistance ) {

            return Vector3.zero;
        }

        if ( intersectionAmount == 0f ) {

            intersectionAmount = Random.Range( -Time.deltaTime, Time.deltaTime );
        }

        var intersectionDirection = deltaVector / intersectionAmount;

        return intersectionDirection * ( maxDistance - intersectionAmount );
    }
コード例 #3
0
    public bool Intersects( SimpleSphereCollider otherCollider )
    {
        if ( !otherCollider.enabled ) {

            return false;
        }

        return IntersectsInternal( transform.position, radius, otherCollider.transform.position, otherCollider.radius );
    }
コード例 #4
0
    public bool Intersects(SimpleSphereCollider otherCollider)
    {
        if (!otherCollider.enabled)
        {
            return(false);
        }

        return(IntersectsInternal(transform.position, radius, otherCollider.transform.position, otherCollider.radius));
    }
コード例 #5
0
    public bool Intersects( SimpleSphereCollider sphereCollider )
    {
        if ( sphereCollider == null || !sphereCollider.enabled ) {

            return false;
        }

        var halfHeight = height * 0.5f;

        var from = center + transform.position - normal * halfHeight;
        var to = from + 2f * ( normal * halfHeight );

        var projectionDistanceNormalized = Vector3.Dot( ( to - from ) / height, sphereCollider.transform.position - from ) / height;

        var projectionPoint = Vector3.Lerp( from, to, projectionDistanceNormalized );

        return IntersectsInternal( projectionPoint, radius, sphereCollider.transform.position, sphereCollider.radius );
    }
コード例 #6
0
    public bool Intersects(SimpleSphereCollider sphereCollider)
    {
        if (sphereCollider == null || !sphereCollider.enabled)
        {
            return(false);
        }

        var halfHeight = height * 0.5f;

        var from = center + transform.position - normal * halfHeight;
        var to   = from + 2f * (normal * halfHeight);

        var projectionDistanceNormalized = Vector3.Dot((to - from) / height, sphereCollider.transform.position - from) / height;

        var projectionPoint = Vector3.Lerp(from, to, projectionDistanceNormalized);

        return(IntersectsInternal(projectionPoint, radius, sphereCollider.transform.position, sphereCollider.radius));
    }
コード例 #7
0
    private Entity CreatePlanetEntity(Entity prefabEntity, List <int> usedIndexes)
    {
        Entity spawnedEntity = EntityManager.Instantiate(prefabEntity);

        RenderMesh renderMesh = EntityManager.GetSharedComponentData <RenderMesh>(spawnedEntity);

        UnityEngine.Material mat = new UnityEngine.Material(renderMesh.material);
        mat.SetVector("_RedMinMax", new UnityEngine.Vector4(_random.NextFloat(0f, 1f), _random.NextFloat(0f, 1f)));
        mat.SetVector("_GreenMinMax", new UnityEngine.Vector4(_random.NextFloat(0f, 1f), _random.NextFloat(0f, 1f)));
        mat.SetVector("_BlueMinMax", new UnityEngine.Vector4(_random.NextFloat(0f, 1f), _random.NextFloat(0f, 1f)));
        mat.SetFloat("_NoiseScale", _random.NextFloat(10f, 80f));
        renderMesh.material = mat;
        EntityManager.SetSharedComponentData(spawnedEntity, renderMesh);

        float rndSize           = _random.NextFloat(1f, 2.5f);
        int   rndOrbitRadiusIdx = _random.NextInt(0, SpawnRadiuses.Length);

        while (usedIndexes.Contains(rndOrbitRadiusIdx))
        {
            rndOrbitRadiusIdx = _random.NextInt(0, SpawnRadiuses.Length);
        }

        float rndOrbitRadius = SpawnRadiuses[rndOrbitRadiusIdx];
        int   rndDir         = _random.NextInt(-5, 6);

        rndDir = rndDir * 2 + 1;
        float movementSpeed = math.sign(rndDir) * 1f * rndSize / rndOrbitRadius;
        float rndPosRadians = _random.NextFloat(0f, math.PI);

        EntityManager.AddComponentData(spawnedEntity, new OrbitRadius {
            Value = rndOrbitRadius
        });
        EntityManager.AddComponentData(spawnedEntity, new MovementSpeed {
            Value = movementSpeed
        });
        EntityManager.AddComponentData(spawnedEntity, new OrbitAngle {
            Value = rndPosRadians
        });
        EntityManager.AddComponentData(spawnedEntity, new Scale {
            Value = rndSize
        });
        EntityManager.AddComponentData(spawnedEntity, new ShootCooldown {
            Value = 0.5f
        });
        EntityManager.AddComponentData(spawnedEntity, new ShootTime {
            Value = 0f
        });
        EntityManager.AddComponentData(spawnedEntity, new AddPlanetHUD());
        EntityManager.AddComponentData(spawnedEntity, new ChangeSphereColliderRadius {
            Value = rndSize * 0.5f
        });
        EntityManager.AddComponentData(spawnedEntity, new NextRocketType {
            Value = 0
        });
        BodyMass planetMass = EntityManager.GetComponentData <BodyMass>(spawnedEntity);

        planetMass.Value *= rndSize;
        EntityManager.SetComponentData(spawnedEntity, planetMass);
        SimpleSphereCollider collider = EntityManager.GetComponentData <SimpleSphereCollider>(spawnedEntity);

        collider.Radius = rndSize * 0.5f;
        EntityManager.SetComponentData(spawnedEntity, collider);
        EntityManager.SetComponentData(spawnedEntity,
                                       new Translation {
            Value = new float3(math.cos(_random.NextFloat(0f, 1f) * math.PI), 0f, math.sin(_random.NextFloat(0f, 1f) * math.PI)) * rndOrbitRadius
        });

        usedIndexes.Add(rndOrbitRadiusIdx);

        return(spawnedEntity);
    }
コード例 #8
0
ファイル: CollisionSystem.cs プロジェクト: OrangeeZ/Crandell
 public bool Intersects(SimpleSphereCollider collider)
 {
     return (collider.transform.position - _center).sqrMagnitude <= (_radius + collider.radius).Pow(2);
 }
コード例 #9
0
ファイル: CollisionSystem.cs プロジェクト: OrangeeZ/LD36
 public bool Intersects(SimpleSphereCollider collider)
 {
     return((collider.transform.position - _center).sqrMagnitude <= (_radius + collider.radius).Pow(2));
 }
コード例 #10
0
 private float GetPosition(SimpleSphereCollider sphereCollider, Axis axis)
 {
     return(sphereCollider.transform.position[(int)axis]);
 }