//每一帧都调用才能让主席进行移动
 public void Move()
 {
     speed = vehicle.Speed;
     if (speed >= 0.01f)
     {
         Vector3 axis = Vector3.Cross(vehicle.Velocity, vehicle.DesiredVelocity);
         direction = Vector3.Angle(vehicle.Velocity, vehicle.DesiredVelocity) / 180.0f * (axis.y < 0 ? -1 : 1);
     }
     locomotion.Do(speed * 6, direction * 180);
 }
 protected void SetupAgentLocomotion()
 {
     if (AgentDone())
     {
         locomotion.Do(0, 0);
     }
     else
     {
         float   speed    = navAgent.desiredVelocity.magnitude;
         Vector3 velocity = Quaternion.Inverse(transform.rotation) * navAgent.desiredVelocity;
         float   angle    = Mathf.Atan2(velocity.x, velocity.z) * 180.0f / Mathf.PI;
         locomotion.Do(speed, angle);
     }
 }
Example #3
0
 void Update()
 {
     if (animator && Camera.main)
     {
         JoystickToEvents.Do(transform, Camera.main.transform, ref speed, ref direction);
         locomotion.Do(speed * 6, direction * 180);
     }
 }
Example #4
0
    void Update()
    {
        if (animator && Camera.main)
        {
            if (transform.tag == "Player")
            {
                JoystickToEvents.Do(transform, Camera.main.transform, ref speed, ref direction);
                locomotion.Do(speed * 6, direction * 180);

                if (Input.GetButtonDown("Fire1"))
                {
                    movement.canMove = false;
                    aimShadow.SetActive(true);
                }
                if (Input.GetButtonUp("Fire1") && canCastAbility1)
                {
                    canShoot = false;
                    locomotion.Attack(1);

                    StartCoroutine(WaitToUseAbility(ability1WaitTime, ability1));
                    StartCoroutine(CancelAnim(1, cancelAnimAt1));
                    //  StartCoroutine(ShootArrow());
                    StartCoroutine(AbilityCooldown(ability1Cooldown, 1));
                }

                if (Input.GetButtonDown("Fire2") && canCastAbility3)
                {
                    locomotion.Attack(3);

                    if (ability3 != null)
                    {
                        StartCoroutine(WaitToUseAbility(ability3WaitTime, ability3));
                        movement.canMove = false;
                        StartCoroutine(AbilityLifeTime(abilityLifetime3, ability3));
                        StartCoroutine(AbilityCooldown(ability1Cooldown, 3));
                    }

                    StartCoroutine(CancelAnim(3, cancelAnimAt3));
                }

                if (Input.GetButtonDown("Fire3"))
                {
                    movement.canMove = false;
                    aimShadow.SetActive(true);
                }
                if (Input.GetButtonUp("Fire3") && canCastAbility2)
                {
                    canShoot = false;
                    locomotion.Attack(1);

                    StartCoroutine(WaitToUseAbility(ability2WaitTime, ability2));
                    StartCoroutine(CancelAnim(1, cancelAnimAt1));
                    //StartCoroutine(ShootArrow());
                    StartCoroutine(AbilityCooldown(ability1Cooldown, 2));
                }
            }
        }
    }
Example #5
0
    private void Update()
    {
        if (mAnimator && Camera.main)
        {
            JoystickToEvents.Do(transform, Camera.main.transform, out mSpeed, out mDirection);
//            mLocomotion.Do(mSpeed * 6, mDirection * 180);
            mLocomotion.Do(mSpeed * 6, mDirection);
        }
    }
    //每一帧都调用才能让主席进行移动
    public void Move()
    {
        speed = vehicle.Speed;
        if (speed >= 0.01f)
        {
            Vector3 axis = Vector3.Cross(vehicle.Velocity, vehicle.DesiredVelocity);
            direction         = Vector3.Angle(vehicle.Velocity, vehicle.DesiredVelocity) / 180.0f * (axis.y < 0 ? -1 : 1);
            previousDirection = direction;
        }
        currentDirection = Mathf.Lerp(previousDirection, direction, Time.deltaTime * changeSpeed);

        currentSpeed = Mathf.Lerp(previousSpeed, speed, Time.deltaTime * changeSpeed);

        locomotion.Do(currentSpeed * 6, currentDirection * 180);

        previousDirection = currentDirection;
        previousSpeed     = currentSpeed;
    }
 void Update()
 {
     if (animator)
     {
         if (body.constraints != RigidbodyConstraints.FreezeRotation)
         {
             body.constraints = RigidbodyConstraints.FreezeRotation;
         }
         locomotion.Do(speed, 45 * direction);
     }
 }
Example #8
0
 public void StopWalking()
 {
     this.gameObject.GetComponent <SteerForLeadFollowing>().enabled = false;
     this.gameObject.GetComponent <SteerForAvoid>().enabled         = true;
     speed = vehicle.Speed;
     if (speed != 0f)
     {
         Vector3 axis = Vector3.Cross(transform.forward, leader.transform.position - transform.position);
         direction = Vector3.Angle(transform.forward, leader.transform.position - transform.position) / 180.0f * (axis.y < 0 ? -1 : 1);
     }
     else
     {
         Vector3 axis = Vector3.Cross(vehicle.Velocity, vehicle.DesiredVelocity);
         direction = Vector3.Angle(vehicle.Velocity, vehicle.DesiredVelocity) / 180.0f * (axis.y < 0 ? -1 : 1);
         if (vehicle.Velocity == Vector3.zero && vehicle.DesiredVelocity == Vector3.zero)
         {
             direction = 0f;
         }
     }
     locomotion.Do(speed * 6, direction * 180);
 }
Example #9
0
    void Update()
    {
        if (animator)
        {
            float h = Input.GetAxis("Horizontal");
            float v = Input.GetAxis("Vertical");

            float speed     = (h * h + v * v) * 6;
            float direction = Mathf.Atan2(h, v) * 180.0f / 3.14159f;

            locomotion.Do(speed, direction);
        }
    }
Example #10
0
    protected void SetupAgentLocomotion()
    {
        if (AgentDone())
        {
            locomotion.Do(0, 0);
            if (particleClone != null)
            {
                GameObject.Destroy(particleClone);
                particleClone = null;
            }
        }
        else
        {
            float speed = agent.desiredVelocity.magnitude;

            Vector3 velocity = Quaternion.Inverse(transform.rotation) * agent.desiredVelocity;

            float angle = Mathf.Atan2(velocity.x, velocity.z) * 180.0f / 3.14159f;

            locomotion.Do(speed, angle);
        }
    }
Example #11
0
    void Update()
    {
        if (animator && Camera.main)
        {
            JoystickToEvents.Do(transform, Camera.main.transform, ref speed, ref direction);
            locomotion.Do(this.gameObject, speed * 10, direction * 180);
        }

        {
#if !MOBILE_INPUT
            // Create a ray from the mouse cursor on screen in the direction of the camera.0
            Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);

            // Create a RaycastHit variable to store information about what was hit by the ray.
            RaycastHit floorHit;

            // Perform the raycast and if it hits something on the floor layer...
            if (Physics.Raycast(camRay, out floorHit, camRayLength, floorMask))
            {
                // Create a vector from the player to the point on the floor the raycast from the mouse hit.
                Vector3 playerToMouse = floorHit.point - transform.position;
                // Ensure the vector is entirely along the floor plane.
                playerToMouse.y = 0f;

                // Create a quaternion (rotation) based on looking down the vector from the player to the mouse.
                Quaternion newRotatation = Quaternion.LookRotation(playerToMouse);

                // Set the player's rotation to this new rotation.
                this.transform.rotation = newRotatation;
                //playerRigidbody.MoveRotation(newRotatation);
            }
#else
            Vector3 turnDir = new Vector3(CrossPlatformInputManager.GetAxisRaw("Mouse X"), 0f, CrossPlatformInputManager.GetAxisRaw("Mouse Y"));

            if (turnDir != Vector3.zero)
            {
                // Create a vector from the player to the point on the floor the raycast from the mouse hit.
                Vector3 playerToMouse = (transform.position + turnDir) - transform.position;

                // Ensure the vector is entirely along the floor plane.
                playerToMouse.y = 0f;

                // Create a quaternion (rotation) based on looking down the vector from the player to the mouse.
                Quaternion newRotatation = Quaternion.LookRotation(playerToMouse);

                // Set the player's rotation to this new rotation.
                this.transform.rotation = newRotatation;
            }
#endif
        }
    }
Example #12
0
    //SETUP LOCOMOTION
    protected void SetupAgentLocomotion()
    {
        targetSpeed = navMeshAgent.desiredVelocity.magnitude;
        targetSpeed = navMeshAgent.pathPending ? 0 : targetSpeed;
        targetSpeed = Mathf.Min(targetSpeed, 5);

        Quaternion rotTemp = Quaternion.Inverse(transform.rotation);

        velocity    = rotTemp * navMeshAgent.desiredVelocity;
        targetAngle = Mathf.Atan2(velocity.x, velocity.z) * 180.0f / 3.14159f;


        locomotion.Do(targetSpeed, targetAngle);
        StrafeMovement(1 /*0.25f*/);
    }
Example #13
0
 void Update()
 {
     if (animator && Camera.main)
     {
         if (transform.tag == "Player1")
         {
             player_num = 1;
         }
         else if (transform.tag == "Player2")
         {
             player_num = 2;
         }
         JoystickToEvents.Do(transform, Camera.main.transform, ref speed, ref direction, player_num);
         locomotion.Do(speed * 6, direction * 180);
     }
 }
Example #14
0
    void Update()
    {
        if (m_Locomotion == null)
        {
            m_Locomotion = new Locomotion(m_Animator);
        }

        if (m_Animator && Camera.main)
        {
            JoystickToWorld.ComputeSpeedDirection(transform, ref m_Speed, ref m_Direction);
        }


        m_Locomotion.Do(m_Speed * 6, m_Direction * 180);

        m_Animator.SetBool("HoldLog", hasLog);
    }
Example #15
0
    void Update()
    {
        if (animator && Camera.main)
        {
            JoystickToEvents.Do(transform, Camera.main.transform, ref speed, ref direction);
            //locomotion.Do(speed * 6, direction * 180);
            locomotion.Do(speed * speed_val, direction * 180);
            animator.speed = speed_val2; //(xx f = 10.0f ���j

            // ���٣�
            AnimatorStateInfo state = animator.GetCurrentAnimatorStateInfo(0);
            bool inWalkRun          = state.IsName("Locomotion.WalkRun");
            if (inWalkRun)
            {
                transform.position += transform.TransformDirection(Vector3.forward * speed / 10);
            }
        }
    }
Example #16
0
    private void Move()
    {
        var mouseHorizontal = Input.GetAxis("Mouse X");

        _horizontal = (_horizontal + _turnSpeed * mouseHorizontal) % 360f;
        _targetMoveTransform.rotation = Quaternion.AngleAxis(_horizontal, Vector3.up);

        if (_currentState == 0)
        {
            _targetMoveTransform.Translate(0, 0, 0);
            _locomotion.Do(0, 0);
        }
        if (_currentState == 1)
        {
            _targetMoveTransform.Translate(0, 0, WalkSpeed * Time.deltaTime);
            _locomotion.Do(0, 0);
        }
        if (_currentState == 2)
        {
            _targetMoveTransform.Translate(0, 0, RunSpeed * Time.deltaTime);
            _locomotion.Do(1000, 0);
        }
        if (_currentState == 3)
        {
            _targetMoveTransform.Translate(0, 0, WalkBackSpeed * Time.deltaTime);
            _locomotion.Do(-1000, 0);
        }
        if (_currentState == 4)
        {
            _targetMoveTransform.Translate(WalkRightSpeed * Time.deltaTime, 0, 0);
            _locomotion.Do(1000, 90);
        }
        if (_currentState == 5)
        {
            _targetMoveTransform.Translate(WalkLeftSpeed * Time.deltaTime, 0, 0);
            _locomotion.Do(1000, -90);
        }
    }
Example #17
0
    void UpdateVelocity()
    {
        if (animator == null || m_Entity == null)
        {
            return;
        }

//        desiredMovementEffect = Mathf.Lerp(desiredMovementEffect.magnitude, 0.0f, 0.1f) * desiredMovementEffect.normalized;

        bool rootMotion = desiredMovementEffect.sqrMagnitude < 0.25f * 0.25f && (m_Entity.netCmpt == null || m_Entity.netCmpt.IsController);

        animator.applyRootMotion = rootMotion;

        if (desiredMovementEffect.sqrMagnitude < 0.25f * 0.25f)
        {
            float speed = 0.0f;

            if (m_Entity.netCmpt == null || m_Entity.netCmpt.IsController)
            {
                if (desiredVelocity != Vector3.zero)
                {
                    if (speedState == SpeedState.Retreat)
                    {
                        speed = -maxForwardSpeed;
                    }
                    else
                    {
                        speed = maxForwardSpeed;
                    }
                }
            }
            else
            {
                if (velocity.sqrMagnitude > 0.1f * 0.1f)
                {
                    Vector3 direction = Util.ProjectOntoPlane(velocity, transform.up);
                    if (Vector3.Dot(transform.forward, direction.normalized) > 0 || Vector3.Angle(transform.forward, direction.normalized) < 165)
                    {
                        speed = maxForwardSpeed;
                    }
                    else
                    {
                        speed = -maxForwardSpeed;
                    }
                }
            }

            float angle = animator.GetFloat("Angle");

            locomotion.Do(speed, angle);
        }
        else
        {
            if (desiredMovementEffect.sqrMagnitude < 0.9f * 0.9f && rigid.velocity.sqrMagnitude < 1f * 1f)
            {
                desiredMovementEffect = Vector3.zero;
            }

            Vector3 velocity = rigid.velocity;

            if (grounded)
            {
                velocity = Util.ProjectOntoPlane(velocity, transform.up);
            }

            Vector3 newVelocity = desiredMovementEffect;

            Vector3 velocityChange = (newVelocity - velocity);

            rigid.AddForce(velocityChange, ForceMode.VelocityChange);
        }
    }
Example #18
0
    private static void Update(float curTime, float deltaTime)
    {
        if (!PlayerCtrlManager.bControl || PlayerCtrlManager.agentObj == null || !PlayerCtrlManager.agentObj.animator)
        {
            return;
        }
        Animator   animator   = PlayerCtrlManager.agentObj.animator;
        Locomotion locomotion = PlayerCtrlManager.agentObj.locomotion;

        if (InputManager.GetKeyDown(KEY_ACTION.MOUSE_RIGHT, false) || InputManager.GetKeyUp(KEY_ACTION.MOUSE_RIGHT, false) || InputManager.GetKeyDown(KEY_ACTION.CAMERA_LEFT, false) || InputManager.GetKeyDown(KEY_ACTION.CAMERA_RIGHT, false) || InputManager.GetKeyUp(KEY_ACTION.CAMERA_LEFT, false) || InputManager.GetKeyUp(KEY_ACTION.CAMERA_RIGHT, false))
        {
            PlayerCtrlManager.LastForward = PlayerCtrlManager.MainCam.forward;
        }

        if (Input.anyKeyDown)
        {
            //if (PlayerCtrlManager.CanChangeState && InputManager.GetKeyDown(KEY_ACTION.CHAGNESTATE, false))
            //{
            //    AnimCtrlScript component = animator.GetComponent<AnimCtrlScript>();
            //    if (component != null)
            //    {
            //        component.ActiveBattle(animator.GetLayerWeight(1) <= 0.5f);
            //    }
            //}

            //if (PlayerCtrlManager.bCanTab && InputManager.GetKeyDown(KEY_ACTION.TAB, false) && GameStateManager.CurGameState != GameState.Battle && (PlayerCtrlManager.charCtrler.isGrounded || Physics.Raycast(PlayerCtrlManager.agentObj.transform.position, Vector3.down, 0.07f)) && !PlayerCtrlManager.agentObj.IsJump)
            //{
            //    PlayersManager.TabPlayer();
            //}

            //if (InputManager.GetKeyDown(KEY_ACTION.ACTION, false) && !PlayerCtrlManager.agentObj.IsJump)
            //{
            //    PalNPC palNPC = PlayerCtrlManager.agentObj.palNPC;
            //    if (palNPC != null && palNPC.perception != null)
            //    {
            //        if (palNPC.interActs.Count < 1)
            //        {
            //            Transform transform = null;
            //            float num = 10000f;
            //            foreach (Transform current in palNPC.perception.hostsCanBeSeen)
            //            {
            //                Vector3 vector = current.gameObject.GetModelObj(false).transform.position - PlayerCtrlManager.agentObj.transform.position;
            //                if (vector.magnitude < num)
            //                {
            //                    num = vector.magnitude;
            //                    transform = current;
            //                }
            //            }
            //            if (transform != null)
            //            {
            //                Interact component2 = transform.GetComponent<Interact>();
            //                if (component2 != null)
            //                {
            //                    float num2 = PlayerCtrlManager.agentObj.ActionRadius;
            //                    MouseEnterCursor componentInChildren = component2.GetComponentInChildren<MouseEnterCursor>();
            //                    if (componentInChildren != null && CursorScriptTemp.Instance.tempTypeDic.ContainsKey(componentInChildren.curState))
            //                    {
            //                        num2 = CursorScriptTemp.Instance.tempTypeDic[componentInChildren.curState].dis;
            //                    }
            //                    if (num < num2)
            //                    {
            //                        component2.InterAct();
            //                    }
            //                }
            //            }
            //        }
            //        else
            //        {
            //            Interact.LastInteractNPC = palNPC.gameObject;
            //            palNPC.interActs[0].InterAct();
            //        }
            //    }
            //}
        }

        if (InputManager.GetKeyDown(KEY_ACTION.JUMP, false) && PlayerCtrlManager.ProcessSpaceKey != null)
        {
            //SlideDown instance = SlideDown.Instance;
            //if (instance != null)
            //{
            //    if (instance.CanJump())
            //    {
            //        SlideDown.Instance.enabled = false;
            //        PlayerCtrlManager.ProcessSpaceKey(PlayerCtrlManager.agentObj);
            //    }
            //}
            //else
            //{
            //    PlayerCtrlManager.ProcessSpaceKey(PlayerCtrlManager.agentObj);
            //}
        }

        //if (PlayerCtrlManager.agentObj.IsInSky && PlayerCtrlManager.agentObj.CanSmallMove && InputManager.curKeyDir != KeyDirection.NONE)
        //{
        //    PlayerCtrlManager.agentObj.CanSmallMove = false;
        //    Vector3 curMoveDir = PlayerCtrlManager.GetCurMoveDir();
        //    Transform transform2 = PlayerCtrlManager.agentObj.transform;
        //    locomotion.ZhiKongSpeedVec = curMoveDir.normalized;
        //    locomotion.ZhiKongSpeedVec.y = 0f;
        //    locomotion.ZhiKongSpeedVec *= PlayerCtrlManager.agentObj.SmallMoveSpeed;
        //    PlayerCtrlManager.agentObj.CanSlowByKeyUp = true;
        //}

        //if (PlayerCtrlManager.agentObj.IsInSky && PlayerCtrlManager.agentObj.CanSlowByKeyUp && InputManager.curKeyDir == KeyDirection.NONE)
        //{
        //    PlayerCtrlManager.agentObj.SlowDownVel();
        //}

        if (!InputManager.GetKey(KEY_ACTION.WALK, false))
        {
            if (PlayerCtrlManager.agentObj.CurSpeed < PlayerCtrlManager.agentObj.RunSpeed - 0.01f)
            {
                PlayerCtrlManager.agentObj.CurSpeed = Mathf.Lerp(PlayerCtrlManager.agentObj.CurSpeed, PlayerCtrlManager.agentObj.RunSpeed, PlayerCtrlManager.agentObj.dampSpeed * Time.deltaTime);
            }
            else if (PlayerCtrlManager.agentObj.CurSpeed > PlayerCtrlManager.agentObj.RunSpeed)
            {
                PlayerCtrlManager.agentObj.CurSpeed = PlayerCtrlManager.agentObj.RunSpeed;
            }
        }
        else if (PlayerCtrlManager.agentObj.CurSpeed > PlayerCtrlManager.agentObj.WalkSpeed + 0.01f)
        {
            PlayerCtrlManager.agentObj.CurSpeed = Mathf.Lerp(PlayerCtrlManager.agentObj.CurSpeed, PlayerCtrlManager.agentObj.WalkSpeed, PlayerCtrlManager.agentObj.dampSpeed * 0.7f * Time.deltaTime);
        }
        else if (PlayerCtrlManager.agentObj.CurSpeed < PlayerCtrlManager.agentObj.WalkSpeed)
        {
            PlayerCtrlManager.agentObj.CurSpeed = PlayerCtrlManager.agentObj.WalkSpeed;
        }

        if (InputManager.GetKeyDown(KEY_ACTION.MOUSE_LEFT, false))
        {
            if (PlayerCtrlManager.CurControlModel == PlayerCtrlManager.PlayerControlModel.Mouse1)
            {
                //MessageProcess.Instance.AddMess(Message.Style.EndAction, new Action(PlayerCtrlManager.OnMouseMove));
            }
            else
            {
                //MessageProcess.Instance.AddMess(Message.Style.Action, new Action(PlayerCtrlManager.OnMouseMove));
            }
        }

        if (PlayerCtrlManager.MouseLeftDown && InputManager.GetKey(KEY_ACTION.MOUSE_LEFT, false) && PlayerCtrlManager.CurControlModel != PlayerCtrlManager.PlayerControlModel.Mouse1 && PlayerCtrlManager.CurControlModel != PlayerCtrlManager.PlayerControlModel.Mouse2)
        {
            if (Vector3.SqrMagnitude(Input.mousePosition - PlayerCtrlManager.MouseLeftDownPos) > 4f)
            {
                PlayerCtrlManager.MouseLeftMove = true;
            }

            //if (!PlayerCtrlManager.MouseLeftMove && Time.time - PlayerCtrlManager.MouseLeftDownTime > CursorScriptTemp.Instance.followCursorTime)
            //{
            //    SmoothFollow2 component3 = Camera.main.GetComponent<SmoothFollow2>();
            //    if (component3 != null)
            //    {
            //        component3.bControl = false;
            //    }
            //    PlayerCtrlManager.CurControlModel = PlayerCtrlManager.PlayerControlModel.Mouse1;
            //    CursorScriptTemp.CursorShow = null;
            //    CursorScriptTemp.Instance.CursorTexToState(CursorTextureState.FollowCursor, -1f);
            //    PalMain.Instance.StartCoroutine(PlayerCtrlManager.DelayShow());
            //}
        }

        //if (InputManager.GetKeyUp(KEY_ACTION.MOUSE_LEFT, false))
        //{
        //    UnityEngine.Debug.Log("MouseLeftDown = false");
        //    PlayerCtrlManager.MouseLeftDown = false;
        //    if (PlayerCtrlManager.curControlModel == PlayerCtrlManager.PlayerControlModel.Mouse1 || PlayerCtrlManager.curControlModel == PlayerCtrlManager.PlayerControlModel.Mouse2)
        //    {
        //        MessageProcess.Instance.AddMess(Message.Style.EndAction, new Action(PlayerCtrlManager.OnMouseUp));
        //    }
        //}

        //if (InputManager.GetKeyDown(KEY_ACTION.AUTO_WALK, false))
        //{
        //    if (PlayerCtrlManager.CurControlModel != PlayerCtrlManager.PlayerControlModel.Auto)
        //    {
        //        PlayerCtrlManager.CurControlModel = PlayerCtrlManager.PlayerControlModel.Auto;
        //    }
        //    else
        //    {
        //        PlayerCtrlManager.CurControlModel = PlayerCtrlManager.PlayerControlModel.None;
        //    }
        //}

        if (InputManager.GetKey(KEY_ACTION.UP, false) || InputManager.GetKey(KEY_ACTION.DOWN, false) || InputManager.GetKey(KEY_ACTION.LEFT, false) || InputManager.GetKey(KEY_ACTION.RIGHT, false) || InputManager.GetKey(KEY_ACTION.UPARROW, false) || InputManager.GetKey(KEY_ACTION.DOWNARROW, false) || InputManager.GetKey(KEY_ACTION.LEFTARROW, false) || InputManager.GetKey(KEY_ACTION.RIGHTARROW, false))
        {
            PlayerCtrlManager.CurControlModel = PlayerCtrlManager.PlayerControlModel.Keyboard;
        }
        else if (PlayerCtrlManager.MouseLeftDown && InputManager.GetKey(KEY_ACTION.MOUSE_LEFT, false) && InputManager.GetKey(KEY_ACTION.MOUSE_RIGHT, false))
        {
            PlayerCtrlManager.CurControlModel = PlayerCtrlManager.PlayerControlModel.Mouse2;
        }
        else if (PlayerCtrlManager.CurControlModel != PlayerCtrlManager.PlayerControlModel.Auto && PlayerCtrlManager.CurControlModel != PlayerCtrlManager.PlayerControlModel.Mouse1)
        {
            PlayerCtrlManager.CurControlModel = PlayerCtrlManager.PlayerControlModel.None;
        }

        TurnHead2 component4 = PlayersManager.Player.GetModelObj(false).GetComponent <TurnHead2>();

        if (PlayerCtrlManager.CurControlModel == PlayerCtrlManager.PlayerControlModel.Keyboard || PlayerCtrlManager.CurControlModel == PlayerCtrlManager.PlayerControlModel.Mouse2 || PlayerCtrlManager.CurControlModel == PlayerCtrlManager.PlayerControlModel.Mouse1 || PlayerCtrlManager.CurControlModel == PlayerCtrlManager.PlayerControlModel.Auto)
        {
            Vector3 forward = animator.transform.forward;
            forward.y = 0f;
            Vector3 dir = InputManager.GetDir();
            if (PlayerCtrlManager.CurControlModel == PlayerCtrlManager.PlayerControlModel.Auto)
            {
                dir.z = 1f;
            }
            else if (PlayerCtrlManager.CurControlModel == PlayerCtrlManager.PlayerControlModel.Mouse2)
            {
                dir.z = 1f;
            }
            else if (PlayerCtrlManager.CurControlModel == PlayerCtrlManager.PlayerControlModel.Mouse1)
            {
                PlayerCtrlManager.PlayerScenePos   = Camera.main.WorldToScreenPoint(PlayerCtrlManager.agentObj.transform.position);
                PlayerCtrlManager.PlayerScenePos.z = 0f;
                PlayerCtrlManager.tempDirection    = Input.mousePosition - PlayerCtrlManager.PlayerScenePos;
                PlayerCtrlManager.tempDirection.Normalize();
                if (PlayerCtrlManager.PlayerScenePos.y < 0f && Input.mousePosition.y < 15f)
                {
                    PlayerCtrlManager.tempDirection.y = -1f;
                }
                dir.x = PlayerCtrlManager.tempDirection.x;
                dir.z = PlayerCtrlManager.tempDirection.y;
            }

            if (dir != Vector3.zero)
            {
                if (!animator.GetBool(PlayerCtrlManager.MoveID))
                {
                    animator.SetBool(PlayerCtrlManager.MoveID, true);
                }
                dir.Normalize();
                Vector3 vector2;
                if (InputManager.GetKey(KEY_ACTION.MOUSE_RIGHT, false) || InputManager.GetKey(KEY_ACTION.CAMERA_LEFT, false) || InputManager.GetKey(KEY_ACTION.CAMERA_RIGHT, false))
                {
                    vector2 = PlayerCtrlManager.MainCam.forward;
                    animator.SetBool("YuanDiZou", false);
                    PlayerCtrlManager.RRoundUp = true;
                }
                else
                {
                    vector2 = PlayerCtrlManager.LastForward;
                }
                vector2.y = 0f;
                PlayerCtrlManager.angle = Vector3.Angle(Vector3.forward, vector2);
                PlayerCtrlManager.cross = Vector3.Cross(Vector3.forward, vector2);
                if (PlayerCtrlManager.cross.y < -0.001f)
                {
                    PlayerCtrlManager.angle = 360f - PlayerCtrlManager.angle;
                }
                PlayerCtrlManager.referentialShift = Quaternion.AngleAxis(PlayerCtrlManager.angle, Vector3.up);
                PlayerCtrlManager.moveDirection    = PlayerCtrlManager.referentialShift * dir;
                PlayerCtrlManager.moveDirection.y  = 0f;
                if (!PlayerCtrlManager.agentObj.IsInSky)
                {
                    float num3 = Vector3.Angle(forward, PlayerCtrlManager.moveDirection);
                    PlayerCtrlManager.speed = Mathf.Lerp(PlayerCtrlManager.speed, PlayerCtrlManager.agentObj.CurSpeed, Time.deltaTime * PlayerCtrlManager.agentObj.dampSpeed);
                    float num4 = PlayerCtrlManager.speed;

                    if (PlayerCtrlManager.UseSunddenlyTurn && (!InputManager.GetKey(KEY_ACTION.MOUSE_RIGHT, false) || PlayerCtrlManager.agentObj.CurSpeed > PlayerCtrlManager.agentObj.WalkSpeed) && num3 > 135f && !PlayerCtrlManager.agentObj.IsInSky)
                    {
                        PlayerCtrlManager.agentObj.transform.forward = PlayerCtrlManager.moveDirection;
                        num3 = 0f;
                    }

                    if (PlayerCtrlManager.agentObj.CurSpeed <= PlayerCtrlManager.agentObj.WalkSpeed && InputManager.GetKey(KEY_ACTION.MOUSE_RIGHT, false) && num3 > 100f && num4 > 0f)
                    {
                        num4 *= -1f;
                    }

                    if (Vector3.Cross(forward, PlayerCtrlManager.moveDirection).y < 0f)
                    {
                        num3 *= -1f;
                    }
                    locomotion.Do(num4, num3, PlayerCtrlManager.agentObj.transform, PlayerCtrlManager.moveDirection);
                }
            }
            else
            {
                PlayerCtrlManager.CurControlModel = PlayerCtrlManager.PlayerControlModel.None;
            }
        }

        if (PlayerCtrlManager.CurControlModel == PlayerCtrlManager.PlayerControlModel.None)
        {
            //float @float = animator.GetFloat("Speed");
            //if (Mathf.Abs(@float) > 0.01f)
            //{
            //    PlayerCtrlManager.speed = 0f;
            //    locomotion.Do(0f, 0f, PlayerCtrlManager.agentObj.transform, PlayerCtrlManager.moveDirection);
            //}
            //else
            //{
            //    animator.SetFloat("Speed", 0f);
            //    bool @bool = animator.GetBool(PlayerCtrlManager.MoveID);
            //    if (@bool)
            //    {
            //        animator.SetBool(PlayerCtrlManager.MoveID, false);
            //    }
            //}
            //if ((InputManager.GetKey(KEY_ACTION.MOUSE_RIGHT, false) || InputManager.GetKey(KEY_ACTION.CAMERA_LEFT, false) || InputManager.GetKey(KEY_ACTION.CAMERA_RIGHT, false)) && !PlayerCtrlManager.agentObj.IsJump)
            //{
            //    if (PlayerCtrlManager.RRoundUp)
            //    {
            //        PlayerCtrlManager.RRoundUp = false;
            //    }
            //    PlayerCtrlManager.TempForward = PlayerCtrlManager.MainCam.forward;
            //    PlayerCtrlManager.TempForward.y = 0f;
            //    Vector3 forward2 = PlayerCtrlManager.agentObj.transform.forward;
            //    forward2.y = 0f;
            //    float num5 = Vector3.Angle(PlayerCtrlManager.TempForward, forward2);
            //    if (num5 > 0.4f)
            //    {
            //        animator.SetBool("YuanDiZou", true);
            //        num5 = ((num5 <= 100f) ? num5 : 100f);
            //        PlayerCtrlManager.lookAtWeight = num5 / 100f;
            //        if (Vector3.Cross(forward2, PlayerCtrlManager.TempForward).y < 0f)
            //        {
            //            num5 = -num5;
            //        }
            //        Transform transform3 = PlayerCtrlManager.agentObj.transform;
            //        Transform transform4 = GameObjectPath.GetEyeObjs(transform3)[0];
            //        float num6 = transform4.position.y - transform3.position.y;
            //        Quaternion rotation = Quaternion.AngleAxis(num5, transform3.up);
            //        Vector3 target = rotation * transform3.forward * 10f + transform3.position;
            //        target.y = transform3.position.y + num6;
            //        component4.target = target;
            //    }
            //    else if (num5 < 0.01f)
            //    {
            //        animator.SetBool("YuanDiZou", false);
            //        PlayerCtrlManager.RRoundUp = true;
            //    }
            //    PlayerCtrlManager.agentObj.transform.forward = Vector3.RotateTowards(PlayerCtrlManager.agentObj.transform.forward, PlayerCtrlManager.TempForward, deltaTime * locomotion.ORotSpeed, deltaTime * locomotion.ORotSpeed);
            //}
            //else if (!PlayerCtrlManager.agentObj.IsInSky)
            //{
            //    if (PlayerCtrlManager.XiuXianDelay <= 0f)
            //    {
            //        float layerWeight = animator.GetLayerWeight(1);
            //        if (layerWeight <= 0f)
            //        {
            //            animator.CrossFade("yidongState.XiuXian", 0.05f);
            //        }
            //        PlayerCtrlManager.XiuXianDelay = UnityEngine.Random.Range(10f, 25f);
            //    }
            //    else
            //    {
            //        PlayerCtrlManager.XiuXianDelay -= Time.deltaTime;
            //    }
            //}
            //if (InputManager.GetKeyUp(KEY_ACTION.MOUSE_RIGHT, false) || InputManager.GetKeyUp(KEY_ACTION.CAMERA_LEFT, false) || InputManager.GetKeyUp(KEY_ACTION.CAMERA_RIGHT, false))
            //{
            //    animator.SetBool("YuanDiZou", false);
            //    PlayerCtrlManager.RRoundUp = true;
            //}
            //if (PlayerCtrlManager.RRoundUp)
            //{
            //    PlayerCtrlManager.lookAtWeight -= deltaTime;
            //    if (PlayerCtrlManager.lookAtWeight <= 0f)
            //    {
            //        PlayerCtrlManager.RRoundUp = false;
            //        PlayerCtrlManager.lookAtWeight = 0f;
            //        component4.lookAtWeight = 0f;
            //    }
            //}
        }
        else
        {
            //PlayerCtrlManager.lookAtWeight = 0f;
            //component4.lookAtWeight = 0f;
            //if (PlayerCtrlManager.XiuXianDelay <= 0f)
            //{
            //    PlayerCtrlManager.XiuXianDelay = UnityEngine.Random.Range(10f, 25f);
            //}
        }

        if (PlayerCtrlManager.lookAtWeight > 0f)
        {
            //component4.lookAtWeight = PlayerCtrlManager.lookAtWeight;
        }

        //PlayerCtrlManager.agentObj.AgentUpdate();
        if (PlayerCtrlManager.agentObj.IsInSky)
        {
            //PlayerCtrlManager.CheckReset();
        }
    }
Example #19
0
    /// <summary>
    /// The actual walking function, which can be controlled from outside the script.
    /// The function must be called every frame in the Updata()-Loop in order to keep the character walking to the goal.
    /// <param name="CurrentGoal">The Transform the character should walk to. </param>
    /// <param name="DrawPath">Bool stating whether the path should be drawn as a line in the scene view.</param>
    /// <param name="maxspeed">A value from 0 to 1 stating how fast the character should walk (1 = maximum speed, typically running).</param>
    /// <param name="mindist">How close the character should approach the goal. If character tends to walk "into" the goal, set this value a little higher.</param>
    /// <param name="anglecut">Angle in degrees at which character does not walk a curve, but turns around standing. I typically choose 120.</param>
    /// </summary>
    public bool WalkTo(Transform CurrentGoal, bool DrawPath, float maxspeed, float mindist, float anglecut)
    {
        bool GoalReached = false;

        if (CurrentGoal != GoalLastFrame)  // check automatically when goal changes, without being told from outside the function
        {
            SlowingDown         = true;
            CurrentGoalCollider = CurrentGoal.GetComponent <Collider>();
        }
        GoalLastFrame = CurrentGoal;

        // Before walking to new goal, slow down. Start walking for new goal once movement is stopped (or, if already standing, immediately).
        if (SlowingDown)
        {
            speed     = speed * 0.95f; // slow down: The closer the value gets to 1, the softer the slowing down.
            direction = 0;

            if (speed < 0.02) // only continue walking to new target when speed is almost 0. (Value will be below 0.02 after 63 frames when speed was 0.5 and slow-down factor is .95.)
            {
                SlowingDown  = false;
                PointsOnPath = FindPathToGoal(transform.position, CurrentGoal.position);
                whereOnPath  = 100; // set first subgoal 100cm away from agent. Otherwise the first subgoal will be exactly at the agent's position, possibly causing confusion.
                nWaypoints   = PointsOnPath.GetLength(0);
            }
        }

        // if goal moves, continuously look for path
        if (CurrentGoal != null)
        {
            if (Vector3.Magnitude(GoalPosition - CurrentGoal.position) > .01f)

            {
                PointsOnPath = FindPathToGoal(transform.position, CurrentGoal.position);
                whereOnPath  = 100;
                nWaypoints   = PointsOnPath.GetLength(0);
            }
            GoalPosition = CurrentGoal.position;
        }


        // Compute speed and direction according to path to goal and distance to goal
        if (CurrentGoal != null && SlowingDown == false)
        {
            //DetermineSpeedAndDirection(out speed, out direction);
            //whereOnPath = DetermineSpeedAndDirection(CurrentGoal, CurrentGoalCollider, mindist, maxspeed, whereOnPath, nWaypoints, PointsOnPath, out speed, out direction);

            if (CurrentGoalCollider != null)
            {
                VectorToTarget = transform.position - CurrentGoalCollider.ClosestPointOnBounds(transform.position);
            }                                                                                                                                        //get distance not to goal, but to its outer boundary, if it has collider
            else
            {
                VectorToTarget = transform.position - CurrentGoal.position;
            }
            VectorToTarget.y = 0; // don't look at y difference
            float DistanceToTarget;
            DistanceToTarget = VectorToTarget.magnitude;
            speed            = 0; // first set 0 to be robust in cases when speed is not changed in following lines
            if (DistanceToTarget > mindist)
            {
                speed = (DistanceToTarget - mindist) * 0.2f;
            }                                                                                // this value determines slowing down before goal
            if (speed > maxspeed)
            {
                speed = maxspeed;
            }                                           // clamp speed at maximum speed as set in inspector.
            if (DistanceToTarget <= mindist)
            {
                speed = 0f; GoalReached = true;
            }                                                                   // GoalReached = true; } // possible bug: make smaller than mindist
                                                                                // get distance to targetSub (= point on the path that is currently being steered to), and change targetSub when it comes close
                                                                                // leave Pathfinding mode when close to target
            if (DistanceToTarget <= mindist + .2f)
            {
                speed = 0f; GoalReached = true;
            }                                                                          // Goal is "reached" 20cm before stopping. This is safer as stopping point varies by +-10cm and "reached"-detection should be robust.
            if (whereOnPath < nWaypoints)
            {
                targetSub = PointsOnPath[whereOnPath];
            }                                                                        // get new subgoal only if on path
            Vector3 VectorToTargetSub;
            VectorToTargetSub   = transform.position - targetSub;
            VectorToTargetSub.y = 0; // don't look at y difference
            float DistanceToTargetSub;
            DistanceToTargetSub = VectorToTargetSub.magnitude;

            // Switch to next targetSub
            if (DistanceToTargetSub < 0.5f + speed * 2) // moving targetSub further away as speed increases reduces overshoots in angular adaption to path (running of S-curves).
            {
                whereOnPath = whereOnPath + 10;         // 10 should work as long as character is slower than 10/100 units per frame (6 units/sec)
            }
            //if (DistanceToTargetSub < 0.1f) { GoalReached = true; }

            if (whereOnPath > nWaypoints)
            {
                speed = 0;
            }


            // determine angle to targetSub
            Vector3 directionTotargetSub;
            directionTotargetSub = transform.position - targetSub;
            directionTotargetSub = transform.InverseTransformDirection(directionTotargetSub);
            float angle;
            angle = Mathf.Atan2(directionTotargetSub.z, directionTotargetSub.x) * Mathf.Rad2Deg; // turn vector into angle
            angle = angle + 90f;                                                                 // turn round 90°
            if (angle >= 180f)
            {
                angle = angle - 360f;
            }                                            // bring to a value between -180 and 180
            if (angle <= -180f)
            {
                angle = angle + 360f;
            }

            // if in doubt, turn round to the left. This is important when the agent has to turn around
            // by about 180 degrees after changing the goal. Without this adaption, the angle may jump
            // between e.g. -175 and +175 for some frames, causing a jittering animation.
            if (angle < -150 || angle > 150)
            {
                angle = 150;
            }

            // transfer angle to direction
            direction = -angle;
        }

        // draw path as red line (in scene view, not in game view)
        if (DrawPath == true && nWaypoints > 0)
        {
            for (int i = 1; i < nWaypoints - 1; i++)
            {
                Debug.DrawLine(PointsOnPath[i], PointsOnPath[i + 1], Color.red);
            }
        }

        // transfer speed and direction to animator component
        if (animator && CurrentGoal != null)
        {
            locomotion.Do(speed * 6, direction);
        }
        return(GoalReached); // report back if goal has been reached yet
    }
Example #20
0
 public void SetLocomotion()
 {
     _locomotion.Do(speed.Value, angle.Value);
 }