Beispiel #1
0
    public Quaternion GetAngleOnPlanet()
    {
        WorldGeneratorWithChunks closest = GetClosestWorld();

        if (closest == null)
        {
            return(Quaternion.identity);
        }
        Vector3 surfaceNormal = this.transform.position - closest.transform.position;

        if (closest != null)
        {
            float strength  = closest.radius * 2;
            float magnitude = surfaceNormal.magnitude;
            if (magnitude < strength)
            {
                return(Quaternion.FromToRotation(Vector3.up, surfaceNormal));
            }
        }
        return(Quaternion.identity);
    }
Beispiel #2
0
    private void ForceAngle(float forceAngleSpeed)
    {
        WorldGeneratorWithChunks closest = GetClosestWorld();

        if (closest != null)
        {
            Vector3 surfaceNormal = this.transform.position - closest.transform.position;
            float   strength      = closest.radius * 2;
            float   magnitude     = surfaceNormal.magnitude;
            if (magnitude < strength)
            {
                if (isTouchingGround)
                {
                    transform.rotation = Quaternion.FromToRotation(Vector3.up, surfaceNormal);
                }
                else
                {
                    var targetRotation = Quaternion.FromToRotation(Vector3.up, surfaceNormal);
                    transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, forceAngleSpeed * strength * Time.fixedDeltaTime);
                }
            }
        }
    }
Beispiel #3
0
    private WorldGeneratorWithChunks GetClosestWorld()
    {
        WorldGeneratorWithChunks closest = null;
        float distance = Mathf.Infinity;

        foreach (WorldGeneratorWithChunks world in worlds)
        {
            if (world == null || world.transform == null)
            {
                continue;
            }

            float maxDis = world.radius * 2;

            Vector3 direction    = world.transform.position - this.transform.position;
            float   distanceFrom = direction.magnitude;
            if (distanceFrom < distance && distanceFrom < maxDis)
            {
                distance = distanceFrom;
                closest  = world;
            }
        }
        return(closest);
    }
Beispiel #4
0
    private void UpdateCurrentWorld()
    {
        WorldGeneratorWithChunks closest = GetClosestWorld();

        currentWorld = closest;
    }