void FixedUpdate()
        {
            var scroll = Input.GetAxis("Mouse ScrollWheel");

            Boundary yBound = new Boundary(40, 51200);
            Boundary zBound = new Boundary(-102400, 51200);
            Boundary xBound = new Boundary(-51200, 51200);

            if (Math.Abs(scroll) > 0.001)
            {
                var scrollSpeed = (MoveToPos.y / yBound.Max) * 5120;

                if (scroll > 0)
                {
                    MoveToPos.y -= scrollSpeed * 2;
                    MoveToPos.z += scrollSpeed * 1.5f;
                }
                else
                {
                    MoveToPos.y += scrollSpeed * 2;
                    MoveToPos.z -= scrollSpeed * 1.5f;
                }
            }

            float vertical   = Input.GetAxis("Vertical") * MovementSpeed;
            float horizontal = Input.GetAxis("Horizontal") * MovementSpeed;

            MoveToPos = new Vector3(MoveToPos.x + horizontal, MoveToPos.y, MoveToPos.z + vertical);

            // Clamp the camera
            MoveToPos = new Vector3(xBound.Clamp(MoveToPos.x), yBound.Clamp(MoveToPos.y), zBound.Clamp(MoveToPos.z));

            // Lerp it to new position
            transform.localPosition = Vector3.Lerp(transform.localPosition, MoveToPos, Time.deltaTime * 20);
        }
示例#2
0
        /// <summary>
        /// Factory function. This generates a new Plnaet object and returns the Planet class from it.
        /// </summary>
        /// <param name="systemManager">The solar system it exists in</param>
        /// <param name="parent">The parent star.</param>
        /// <param name="swimLane">The area in which the planet can be spawned</param>
        /// <returns></returns>
        public static Planet GeneratePlanet(SolarSystem systemManager, CelestialBody parent, Boundary swimLane)
        {
            // Generate the seed to be used for randoms
            var seed = Rng.GetRandomNumber(int.MinValue, int.MaxValue);

            // Find the planet object and instantiate it.
            var planetObj = GameObject.Find("ObjectPool").GetComponent <ObjectPool>().PlanetObj;

            var obj = Instantiate(planetObj);
            var s   = obj.AddComponent <Planet>();

            s.SystemManager = systemManager;
            s.Seed          = seed;

            s.HostStar = s.SystemManager.Stars.FirstOrDefault();

            // Get a random position within the swimlane
            s.DistanceFromParent = Rng.GetRandomNumber(swimLane, seed);

            // These boundaries are used for the personal properties of the planet.
            var scalar = swimLane.Mean;
            var bound  = new Boundary(0.0000001f * scalar, 0.00001f * scalar);

            s.name        = $"{parent.name} Planet {parent.Children.Count() + 1}";
            s.DisplayName = $"{parent.DisplayName} {parent.Children.Count() + 1}";
            s.Diameter    = Rng.GetRandomNumber(parent.Diameter * bound.Min, parent.Diameter * bound.Max, seed);

            // after getting the first value, reset the bounds to match the original random.'
            // this makes getting huge diameters and tiny mass a thing of the past.
            bound.Min = Boundary.Clamp(0, 1.0f, (s.Diameter / MaximumDiameter) - 0.1f);
            bound.Max = Boundary.Clamp(0, 1.0f, bound.Min + 0.6f);

            s.Mass = Rng.GetRandomNumber(parent.Mass * bound.Min, parent.Mass * bound.Max, seed);

            s.Rotation = Rng.GetRandomNumber(MaximumRotation / -1, MaximumRotation, seed);

            s.Obj    = obj;
            s.Parent = parent;

            s.IsGaseous = s.Density < 0.7;

            s.MaterialWealth = new MineralWealth(s);
            s.Atmosphere     = new Atmosphere(s);

            if (s.Temperature < 100)
            {
                s.Hydrosphere = Rng.GetRandomNumber(0, 1.0f, seed);
            }


            s.Pos = new Vector3(s.Parent.Pos.x, s.Parent.Pos.y, s.Parent.Pos.z + s.DistanceFromParent);
            s.Init();
            return(s);
        }
        public Dictionary <string, float> GenerateElementPercentages(ElementType type, int rngSeed)
        {
            // index / percent
            var dict = new Dictionary <string, float>();

            var percentLeft = 1.0f;

            var        minerals = type == ElementType.Minerals ? Minerals : null;
            List <Gas> gasses   = null;

            if (type == ElementType.Gases)
            {
                gasses = Gasses;
            }
            if (type == ElementType.Atmospherics)
            {
                gasses = Atmospherics;
            }
            if (type == ElementType.GasGiantGases)
            {
                gasses = GasGiantGasses;
            }
            if (type == ElementType.RockyGases)
            {
                gasses = RockyGasses;
            }

            var count = minerals?.Count ?? gasses?.Count ?? -1;

            foreach (var index in MathHelper.SeedNumberList(0, count - 1))
            {
                // there is a 10% chance that this element will no exist
                if (Rng.GetRandomNumber(0, 1.0f, rngSeed) > 0.9f)
                {
                    continue;
                }

                var playingRoom = Boundary.Clamp(0f, 1f,
                                                 percentLeft - (minerals?[index].Commonality ?? gasses?[index].Commonality ?? -1f));
                var percent = Rng.GetRandomNumber(0, playingRoom, rngSeed);
                percentLeft -= playingRoom;
                dict.Add(minerals?[index].Name ?? gasses?[index].Name ?? "NO ELEMENT", percent);
            }

            return(dict);
        }
示例#4
0
        /// <summary>
        /// This will update gameobject changes over the delta time
        /// This takes a bit of time to do and is not threadsafe.
        /// </summary>
        public virtual void VisualUpdate(float deltaTime)
        {
            DistanceToPos = Vector3.Distance(Obj.transform.position, Pos);

            if (MovementSteps.Count != 0)
            {
                var step = Mathf.RoundToInt(MovementGranularity * Clock.DayProgressPercent);

                Boundary.Clamp(0, MovementSteps.Count - 1, ref step);
                Obj.transform.position = MovementSteps[step];
                Pos = MovementSteps[step];
            }
            //Obj.transform.position = Vector3.MoveTowards(Obj.transform.position, Pos, deltaTime*DistanceToPos);
            Obj.transform.rotation = Rot;

            foreach (var ssObject in Children.GetCollection())
            {
                ssObject.VisualUpdate(deltaTime);
            }
        }
示例#5
0
 private void FixedUpdate()
 {
     rb.position = boundary.Clamp(rb.position);
     rb.rotation = Quaternion.Euler(0f, 0f, tilt * rb.velocity.x);
 }