Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using _src.Scripts.PlayerFeatures.PlayerEntity;
- using _src.Scripts.PlayerFeatures.PlayerManagement;
- using _src.Scripts.PlayerFeatures.PlayerManagement.Enums;
- using Invector.vCharacterController;
- using Obi;
- using UnityEngine;
- using Zenject;
- namespace _src.Scripts.Core.Connection
- {
- public class LengthController : MonoBehaviour
- {
- private ObiRope _obiRope;
- private ObiRopeCursor _cursor;
- [SerializeField]
- private float _ropeLengthResizeSpeed = 1;
- [SerializeField]
- private float _ropeMinimalLenght = 1;
- [SerializeField]
- private float _ropeMaximalLenght;
- [SerializeField]
- private List<RopeClimbing.RopeClimbing> _ropeClimbing = new();
- [Inject]
- private PlayersContainer _playersContainer;
- private PlayerEntityAdapter _fathersEntity;
- private PlayerEntityAdapter _sonEntity;
- private float _previousRopeLenght;
- private void Start()
- {
- _fathersEntity = _playersContainer.GetPlayerEntity(PlayerCharacter.Father);
- _sonEntity = _playersContainer.GetPlayerEntity(PlayerCharacter.Son);
- _obiRope = GetComponent<ObiRope>();
- _cursor = GetComponent<ObiRopeCursor>();
- _ropeClimbing[0] = _fathersEntity.GetComponent<RopeClimbing.RopeClimbing>();
- _ropeClimbing[1] = _sonEntity.GetComponent<RopeClimbing.RopeClimbing>();
- _obiRope.OnBeginStep += UpdateRopeLenght;
- }
- private void UpdateRopeLenght(ObiActor actor, float stepTime)
- {
- var playerDistance = Vector3.Distance(_fathersEntity.transform.position, _sonEntity.transform.position);
- _fathersEntity.GetComponent<ObiRigidbody>().kinematicForParticles = !_ropeClimbing[0].IsCatchingRope;
- _sonEntity.GetComponent<ObiRigidbody>().kinematicForParticles = !_ropeClimbing[1].IsCatchingRope;
- if (_obiRope.restLength < _ropeMinimalLenght || !_fathersEntity.VThirdPersonController.isGrounded || !_sonEntity.VThirdPersonController.isGrounded)
- return;
- if (_ropeClimbing[0].IsCatchingRope || _ropeClimbing[1].IsCatchingRope && IsPlayersOnGround())
- {
- if (_previousRopeLenght > playerDistance)
- {
- _cursor.ChangeLength(Mathf.Clamp(playerDistance, _ropeMinimalLenght, _ropeMaximalLenght));
- }
- }
- _previousRopeLenght = playerDistance - 0.01f;
- }
- private bool IsPlayersOnGround()
- => _fathersEntity.VThirdPersonController.isGrounded && _sonEntity.VThirdPersonController.isGrounded;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement