private void Move() { float l_Horizontal = Input.GetAxisRaw("Horizontal"); float l_Vertical = Input.GetAxisRaw("Vertical"); Vector3 l_Direction = new Vector3(l_Horizontal, 0f, l_Vertical).normalized; //if(l_Direction.magnitude >= 0.1f) //{ // float l_TargetAngle = Mathf.Atan2(l_Direction.x, l_Direction.z) * Mathf.Rad2Deg + m_Camera.eulerAngles.y; // float l_Angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, l_TargetAngle, ref m_TurnSmoothVelocity, m_TurnSmoothTime); // transform.rotation = Quaternion.Euler(0f, l_Angle, 0f); // Vector3 l_MoveDir = Quaternion.Euler(0f, l_Angle, 0f) * Vector3.forward; // m_Controller.Move(l_MoveDir.normalized * m_Speed * Time.deltaTime); //} if (Input.GetKey(KeyCode.LeftShift)) { m_PlayerGliding.Glide(m_Camera, m_Controller, l_Direction); } else { m_PlayerWalking.Walk(m_Camera, m_Controller, l_Direction); } m_Velocity.y += m_Gravity * Time.deltaTime; //m_Controller.Move(m_Velocity * Time.deltaTime); }
private void CharacterMovement() { //if (!m_IsSliding) //{ m_Horizontal = Input.GetAxisRaw("Horizontal"); m_Vertical = Input.GetAxisRaw("Vertical"); //} //else //{ // m_Horizontal = 0; // m_Vertical = 0; //} m_Direction = new Vector3(m_Horizontal, 0f, m_Vertical).normalized; if (m_SpiritMode) { m_Direction = m_PlayerGliding.Glide(m_Camera, m_Controller, m_Direction); } else { m_Direction = m_PlayerWalking.Walk(m_Camera, m_Controller, m_Direction); } GravityUpload(); AnimCondWalk(m_Direction); // Application du momentum du grappin m_Direction += m_CharacterVelocityMomentum; // Application de la velocité en pente m_Direction += m_SlopeVelocity; // Application de la direction finale au character controller du personnage m_Controller.Move(m_Direction * Time.deltaTime); // Réduction du momentum if (m_CharacterVelocityMomentum.magnitude > 0f) { float momentumDrag = 3f; m_CharacterVelocityMomentum -= m_CharacterVelocityMomentum * momentumDrag * Time.deltaTime; // Si l'on veut modifier le temps de skidding du personnage au sol, il suffit de changer la valeur (ici 5) à laquelle on compare la magnitude du momentum if (m_CharacterVelocityMomentum.magnitude < 5f) { m_CharacterVelocityMomentum = Vector3.zero; } } // Met à jour les animations du personnage AnimCondGeneral(); }
private void CharacterMovement() { float l_Horizontal = Input.GetAxisRaw("Horizontal"); float l_Vertical = Input.GetAxisRaw("Vertical"); Vector3 l_Direction = new Vector3(l_Horizontal, 0f, l_Vertical).normalized; if (l_Direction != Vector3.zero) { m_PlayerAnim.SetBool("IsMoving", true); } else { m_PlayerAnim.SetBool("IsMoving", false); } if (Input.GetButton("Glide") && m_StaminaComponent.CurrentStamina >= 0 /* Input.GetKey(KeyCode.LeftShift)*/) { l_Direction = m_PlayerGliding.Glide(m_Camera, m_Controller, l_Direction); m_PlayerAnim.SetBool("IsGliding", true); m_Cloth.material = m_GlowMaterial; m_Pagne.material = m_GlowMaterial; //foreach (var clothToReplace in m_Cloth) //{ // clothToReplace.material = m_GlowMaterial; //} m_StaminaComponent.UseStamina(10f * Time.deltaTime); foreach (ParticleSystem glideParticle in m_GlideParticle) { glideParticle.Play(); } } else if (Input.GetButtonUp("Glide")) { m_PlayerGliding.GlideSpeed = 0; m_PlayerWallGliding.EndWallGlide(); m_PlayerAnim.SetBool("IsGliding", false); //for (int i = 0; i < m_Cloth.Length; i++) //{ // m_Cloth[i].material = m_SavedMaterial[i]; //} m_Cloth.material = m_ClothSavedMaterial; m_Pagne.material = m_PagneSavedMaterial; foreach (ParticleSystem glideParticle in m_GlideParticle) { glideParticle.Stop(); } } else { l_Direction = m_PlayerWalking.Walk(m_Camera, m_Controller, l_Direction); } if (!m_PlayerWallGliding.IsWallGliding()) { // Apply gravity to the velocity float gravityDownForce = 0f; if (!Input.GetButton("Glide")) { gravityDownForce = -30f; } else if (Input.GetButton("Glide")) { gravityDownForce = -10f; } m_CharacterVelocityY += gravityDownForce * Time.deltaTime; // Apply Y velocity to move vector l_Direction.y = m_CharacterVelocityY; } else { l_Direction += m_PlayerWallGliding.WallGlideGravity; } // Apply momentum l_Direction += m_CharacterVelocityMomentum; // Move Character Controller m_Controller.Move(l_Direction * Time.deltaTime); // Dampen momentum if (m_CharacterVelocityMomentum.magnitude > 0f) { float momentumDrag = 3f; m_CharacterVelocityMomentum -= m_CharacterVelocityMomentum * momentumDrag * Time.deltaTime; if (m_CharacterVelocityMomentum.magnitude < 1f) { m_CharacterVelocityMomentum = Vector3.zero; } } }