void LateUpdate()
    {
        Vector3 toTarget = followTransform.position - thisTransform.position;

        toTarget.y = 0;
        float distance = toTarget.magnitude;

        toTarget.Normalize();
        if (distance > minFollowDistance)
        {
//			toTarget = toTarget.normalized;
            Vector3 forward = thisTransform.forward;
            forward.y = 0;
            forward   = forward.normalized;
            float   angleToTarget  = Vector3.Angle(forward, toTarget);
            Vector3 localForward   = thisTransform.InverseTransformDirection(toTarget);
            Vector3 localTargetPos = thisTransform.InverseTransformPoint(followTransform.position);
            float   angleRatio     = Mathf.Clamp01(angleToTarget / 90);

            if (angleToTarget > 0.1f)
            {
                if (localTargetPos.x > 0)
                {
                    thisRobot.Rotate(angleRatio);
                }
                else
                if (localTargetPos.x < 0)
                {
                    thisRobot.Rotate(-angleRatio);
                }
            }

//			if ( localTargetPos.z > 0 )
            if (distance > 10)
            {
                thisRobot.Move((distance + 1 - 10) * (1 - angleRatio));                        // lerp walk to run speed
            }
            else
            {
//				if ( distance <= breakingDistance )
                thisRobot.Move(Mathf.Clamp01(Mathf.InverseLerp(minFollowDistance, breakingDistance, distance)) - angleRatio);
            }
//				thisRobot.Move ( 1 - angleRatio );
//			else
//			if ( localTargetPos.z < 0 )
//				thisRobot.Move ( -1 );

//			thisRobot.Rotate ( angle );
//			if ( angleToTarget > 0.1f )
//				thisRobot.Rotate ( Mathf.Min ( angleToTarget, thisRobot.hRotateSpeed ) * Time.deltaTime * Mathf.Sign ( localForward.x ) );
//			Debug.Log ( "angle is " + angleToTarget + " localforward x is " + localForward.x );
//			Debug.DrawRay ( thisTransform.position + Vector3.up, forward, Color.blue );
//			Debug.DrawRay ( thisTransform.position + Vector3.up, toTarget, Color.red );
            forwardGizmo = forward;
            targetGizmo  = toTarget;
        }
    }
        public IEnumerable <IPosition> Run(string queueOfCommands)
        {
            foreach (char command in queueOfCommands)
            {
                ICommand commandToRun = new CommandFactory().Get(command);

                if (commandToRun is IRotate)
                {
                    IRotate rotateCommand = (IRotate)commandToRun;
                    yield return(_robotController.Move(rotateCommand));
                }
                else
                {
                    yield return(_robotController.Move(commandToRun));
                }
            }
        }
示例#3
0
    void LateUpdate()
    {
        if (manualInput.controllable)
        {
            return;
        }
        if (robot.IsTurningInPlace)
        {
            return;
        }
        float throttle = ThrottleInput;
        float brake    = BrakeInput;
        float steer    = SteeringAngle;

        robot.Move(throttle, brake);
        robot.RotateRaw(steer);
//		robot.Rotate ( steer );
    }
示例#4
0
    void LateUpdate()
    {
        // check for close app
        if (Input.GetButtonDown("Quit"))
        {
            Application.Quit();
        }

        if (Input.GetButtonDown("Grid"))
        {
            if (grid != null)
            {
                grid.enabled = !grid.enabled;
            }
        }

//		if ( Input.GetKeyDown ( KeyCode.O ) )
//		{
//			if ( objectiveParent != null )
//				objectiveParent.SetActive ( !objectiveParent.activeSelf );
//		}

        if (DisableFocus)
        {
            return;
        }

        bool tempControl = false;

        if (!isTrainingMode)
        {
            controllable = tempControl = Input.GetButton("Vertical") || Input.GetButton("Horizontal");
        }

        // check if we're not focused on our robot
        if (controllable)
        {
            // check for rotation input
            float mouseX   = Input.GetAxis("Mouse X");
            float mouseY   = Input.GetAxis("Mouse Y");
            float keyH     = Input.GetAxis("Horizontal");
            bool  isSaving = controller.IsSaving;
            if (isTrainingMode || tempControl)
            {
                bool isRMBDown = Input.GetMouseButton(1);
                if (mouseX != 0 && !isRMBDown)
                {
                    lastMouseTime = Time.time;
                    hMouseMove   += 4 * Time.deltaTime * Mathf.Sign(mouseX);
                    hMouseMove    = Mathf.Clamp(hMouseMove, -1f, 1f);
                }
                else
                if (Time.time - lastMouseTime > 0.03f)
                {
                    hMouseMove = Mathf.MoveTowards(hMouseMove, 0, Time.deltaTime * 4);
                }

                float hMove = Mathf.Clamp(keyH + hMouseMove, -1f, 1f);
                if (!isSaving)
                {
                    controller.Rotate(hMove);
                }

                if (isRMBDown)
                {
                    controller.RotateCamera(mouseX, mouseY);
                }
            }
//				controller.RotateCamera ( 0, mouseY );
            else
            {
//			if ( !isTrainingMode )
                controller.RotateCamera(mouseX, mouseY);
            }

            // check for camera zoom
            float wheel = Input.GetAxis("Mouse ScrollWheel");
            if (wheel != 0)
            {
                controller.ZoomCamera(-wheel);
            }

            // check to reset zoom
            if (Input.GetMouseButtonDown(2))
            {
                controller.ResetZoom();
            }

            // check for movement input
            if (controller.allowStrafe)
            {
                Vector3 move = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")) * Time.deltaTime;
                move = controller.TransformDirection(move);
//				controller.Move ( move );
            }
            else
            {
                if (braking && Input.GetButtonUp("Vertical"))
                {
                    Input.ResetInputAxes();
                }

                float throttle = Input.GetAxis("Vertical");
                if (throttle != 0 && Mathf.Abs(controller.Speed) > 0.01f && Mathf.Sign(throttle) != Mathf.Sign(controller.Speed))
                {
                    braking = true;
                }
//				else
//					braking = false;
//				if ( braking = true )
                if (throttle == 0)
                {
                    braking = false;
                }
//				Debug.Log ( "vert: " + throttle + " speed: " + controller.Speed + " vsign " + Mathf.Sign ( throttle ) + " vspd " + Mathf.Sign ( controller.Speed ) + " braking " + braking );

//				Debug.Log ( "braking: " + braking);


                if (!isSaving)
                {
                    if (controller.allowSprint)
                    {
                        throttle *= Mathf.Lerp(1, controller.sprintMultiplier, Input.GetAxis("Sprint"));
                    }
                    if (braking)
                    {
                        controller.Move(0, Mathf.Abs(throttle));
                    }
                    else
                    {
                        controller.Move(throttle, 0);
                    }
                }
//				controller.Move ( forward );
            }

//			if ( Input.GetKeyDown ( KeyCode.Space ) )
//			{
//				controller.FixedTurn ( 180, 3 );
//			}

            // check for camera switch key
            if (Input.GetButtonDown("Switch Camera"))
            {
                controller.SwitchCamera();
            }

            // check for unfocus input
            if (Input.GetButtonDown("Unfocus"))
            {
                Unfocus();
                return;
            }

//			Ray ray = controller.camera
//			Physics.Raycast (  )
        }
        else
        {
            if (!isTrainingMode)
            {
                // check for rotation input
                float mouseX = Input.GetAxis("Mouse X");
                float mouseY = Input.GetAxis("Mouse Y");
                controller.RotateCamera(mouseX, mouseY);
                // check for camera zoom
                float wheel = Input.GetAxis("Mouse ScrollWheel");
                if (wheel != 0)
                {
                    controller.ZoomCamera(-wheel);
                }

                // check to reset zoom
                if (Input.GetMouseButtonDown(2))
                {
                    controller.ResetZoom();
                }
            }
            braking = false;
        }
        // check for sample pickup
        if (Input.GetButtonDown("Sample Pickup") || Input.GetButtonDown("Focus / Pickup"))
        {
            if (controllable && controller.IsNearObjective)
            {
                controller.PickupObjective(OnPickedUpObjective);
            }
        }
        // check for focus input
        if (Input.GetButtonDown("Focus / Pickup"))
        {
            Focus();
        }
        if (Input.GetButtonDown("Unfocus"))
        {
            if (controllable)
            {
                Unfocus();
            }
        }
//		if ( Input.GetKeyDown ( KeyCode.Escape ) )
//		{
//			if ( controllable )
//				Unfocus ();
//			else
//				Focus ();
//		}
    }