Example #1
0
    void Update()
    {
        if (currentNode != null)
        {
            float throttle  = 0f;
            var   thrustDir = new Vector2();
            if (Input.GetKey(KeyCode.W))
            {
                throttle    = 1f;
                thrustDir.y = 1f;
            }
            if (Input.GetKey(KeyCode.S))
            {
                throttle    = 1f;
                thrustDir.y = -1f;
            }
            if (Input.GetKey(KeyCode.A))
            {
                throttle    = 1f;
                thrustDir.x = -1f;
            }
            if (Input.GetKey(KeyCode.D))
            {
                throttle    = 1f;
                thrustDir.x = 1f;
            }
            var thrustControl = new ThrustControl()
            {
                Dir      = thrustDir.normalized,
                Throttle = throttle
            };
            currentNode.SendMessage("SetThrust", thrustControl);

            if (Input.GetKeyDown(KeyCode.F))
            {
                currentNode.SendMessage("ToggleFlightAssist");
            }

            Vector2 aimDir = MouseManager.WorldPosition - currentNode.Position2;
            aimDis  = aimDir.magnitude;
            aimDir /= aimDis;

            aimDis = Mathf.Min(aimDis, MaxAimDis);

            CrossHair.Position = currentNode.Position + (Vector3)(aimDir * aimDis);

            currentNode.SendMessage("RotateToDir", aimDir);
        }

        DebugText.Add($"desiredThurst: {desiredThurst}");
    }