void UpdateCharacter() { if (!tno.isMine) { //Debug.LogFormat("{0} updating character with inputs m:{1}", tno.owner.name, m_Move); } // pass all parameters to the character control script Vector3 vizOrigin = transform.position + transform.up * 1; Debug.DrawLine(vizOrigin, vizOrigin + m_Move.normalized, Color.green); if (m_Aim != lastAim) { m_Character.SetAnimValue("Aiming", "BOOL", m_Aim); tno.Send("SetAnimValue", Target.Others, "Aiming", "BOOL", m_Aim); lastAim = m_Aim; } if (m_Move.sqrMagnitude > 1f) { m_Move.Normalize(); } MoveState = m_Character.Move(m_Move, m_TurnAmount, m_stance, m_Jump); m_Jump = false; }
public BattlePlayerMovementState Move(Vector3 move, float turnAmount, BodyStance stance, bool jump) { var moveState = new BattlePlayerMovementState(); if (!started) { return(null); } // convert the world relative moveInput vector into a local-relative // turn amount and forward amount required to head in the desired // direction. CheckGroundStatus(); var speedFactor = m_MoveSpeedMultiplier; speedFactor *= currentStance.SpeedFactor; if (currentStance.StickToGroundAngle) //TODO make a 'myNormal' for the character, break out this code { var oldMove = move; move = Vector3.ProjectOnPlane(move, m_GroundNormal); var uphill = oldMove.y < move.y; var moveSlope = Vector3.Angle(oldMove, move); if (uphill && moveSlope > 5) { speedFactor *= currentStance.AngleSpeedAdjust * moveSlope; } /* * var sign = (!uphill ? "-" : "+"); * Debug.Log("angle is "+ sign+ " " + moveSlope.ToString()); */ Debug.DrawLine(transform.position, transform.position + move * 5, Color.red); } m_Rigidbody.velocity = new Vector3(move.x * speedFactor, m_Rigidbody.velocity.y, move.z * speedFactor); moveState.Velocity = m_Rigidbody.velocity; move = transform.InverseTransformDirection(move); m_ForwardAmount = move.z; m_TurnAmount = turnAmount * m_CursorSensitivity; m_StrafeAmount = move.x; moveState.Move = move; ApplyExtraTurnRotation(); bool crouch = stance == BodyStance.Crouch; m_stance = stance; moveState.Stance = stance; // control and velocity handling is different when grounded and airborne: if (m_IsGrounded) { HandleGroundedMovement(crouch, jump); moveState.Grounded = true; } else { HandleAirborneMovement(); moveState.Grounded = false; } // ScaleCapsuleForCrouching(crouch); // PreventStandingInLowHeadroom(); // send input and other state parameters to the animator UpdateAnimator(move); return(moveState); }