// Update is called once per frame void UpdateLadder() { m_heroBoxComputed = false; // prevent any crash if (m_player == null || m_motor == null) { return; } // Handle dynamic of controlled hero if (m_isControlling) { Settings oSettings = GetSettings(); // update default jump dir float fX = m_player.m_inputs.m_axisX.GetRawValue(); if (fX > 0f) { m_defaultExitDir = true; } else if (fX < 0f) { m_defaultExitDir = false; } // handle jump exit first if (!string.IsNullOrEmpty(m_player.m_jump.m_button)) { bool bJump = Input.GetButton(m_player.m_jump.m_button); m_releaseJump |= !bJump; if (m_releaseJump && bJump && GetSettings().m_canJump) { ReleaseControl(true); return; } } // update velocity m_motor.m_velocity.x = 0f; m_motor.m_velocity.y = APInput.Update(m_motor.m_velocity.y, oSettings.m_maxSpeed * m_player.m_inputs.m_axisY.GetRawValue(), true, oSettings.m_acceleration, oSettings.m_deceleration, Time.deltaTime); // Handle exit and move HandleExit(); m_motor.Move(); } else { if (m_timeForNextCatch > 0f) { m_timeForNextCatch -= Time.deltaTime; } TryTakecontrol(); } }
void HandleHorizontalMove() { m_sliding = false; float maxSpeed = ComputeMaxSpeed(); // compute horizontal velocity from input float fMoveDir = m_inputs.m_axisX.GetRawValue() != 0f ? Mathf.Sign(m_inputs.m_axisX.GetRawValue()) : (m_motor.FaceRight ? 1f : -1f); // compute slope factor m_speedFactor = 1f; if (m_onGround) { float fGroundAngle = Mathf.Rad2Deg * Mathf.Acos(m_motor.GetGroundNormal().y); fGroundAngle = fMoveDir != Mathf.Sign(m_motor.GetGroundNormal().x) ? fGroundAngle : -fGroundAngle; m_speedFactor = Mathf.Clamp01(m_basic.m_slopeSpeedMultiplier.Evaluate(fGroundAngle)); } // Compute move direction Vector2 hrzMoveDir = new Vector2(fMoveDir, 0f); float absAxisX = Mathf.Abs(m_inputs.m_axisX.GetRawValue()); float hrzMoveLength = absAxisX * maxSpeed * m_speedFactor; // align this velocity on ground plane if we touch the ground bool bCrouched = IsCrouched(); bool bAttacking = IsAttacking(); if (m_onGround) { float fDot = Vector2.Dot(hrzMoveDir, m_motor.GetGroundNormal()); if (Mathf.Abs(fDot) > float.Epsilon) { Vector3 perpAxis = Vector3.Cross(hrzMoveDir, m_motor.GetGroundNormal()); hrzMoveDir = Vector3.Cross(m_motor.GetGroundNormal(), perpAxis); hrzMoveDir.Normalize(); } // cancel input if needed if (bCrouched || bAttacking) { hrzMoveLength = 0f; } } // handle dynamic if (m_onGround) { float fDynFriction, fStaticFriction; ComputeFrictions(out fDynFriction, out fStaticFriction); // update sliding status if (fDynFriction < 1f) { m_sliding = true; } float fVelOnMove = Vector2.Dot(m_motor.m_velocity, hrzMoveDir); float fDirLength = fVelOnMove; if (m_sliding) { // dynamic is different while sliding if (!bCrouched && !bAttacking && absAxisX > 0f) { float fDiffMax = maxSpeed - fVelOnMove; if (fDiffMax > 0f) { fDirLength = fVelOnMove + Mathf.Min(fDiffMax, absAxisX * fDynFriction * Time.deltaTime * 20f); } } else { fDirLength = ApplyDamping(fVelOnMove, fStaticFriction); } } else { // raise deceleration for crouched/attack float fDecel = (bCrouched || bAttacking) ? m_basic.m_deceleration * 2f : m_basic.m_deceleration; fDirLength = APInput.Update(fVelOnMove, hrzMoveLength, true, m_basic.m_acceleration, fDecel, Time.deltaTime); } ClampValueWithDamping(ref fDirLength, m_maxAirVelDamping, -maxSpeed, maxSpeed); m_motor.m_velocity = hrzMoveDir * (fDirLength); m_groundSpeed = Mathf.Abs(fDirLength); } else { // in air dynamic float fVelOnMove = Vector2.Dot(m_motor.m_velocity, hrzMoveDir); float fDiffVel = (hrzMoveLength - fVelOnMove); float fMaxAccel = m_basic.m_airPower * Time.deltaTime; fDiffVel = Mathf.Clamp(fDiffVel, -fMaxAccel, fMaxAccel); m_motor.m_velocity += hrzMoveDir * fDiffVel; ClampValueWithDamping(ref m_motor.m_velocity.x, m_maxAirVelDamping, -m_basic.m_maxAirSpeed, m_basic.m_maxAirSpeed); ClampValueWithDamping(ref m_motor.m_velocity.y, m_maxAirVelDamping, -m_basic.m_maxFallSpeed, m_basic.m_maxFallSpeed); m_groundSpeed = 0f; } }