//public Team team; // Use this for initialization protected void Awake() { _characterController = GetComponent <CharacterController>(); _characterController.detectCollisions = false; _rigidbody = GetComponent <Rigidbody>(); floorD = GetComponentInChildren <FloorDetection>(); }
private void handleGround() { // On genere les infos du sol _floorSensor.Cast(); _floorDetection = _floorSensor.GetFloorDetection(); _isOnGround = false; _isSliding = false; if (_floorDetection.detectGround) { // On calcule la velocité vertical en fonction de la normal au sol float YVelocity = Vector3.Project(_momentum, _floorDetection.hitNormal).magnitude; // on determine si on est au sol en fonction de la celocité et de _floorDetection _isOnGround = YVelocity < 0.01f || _floorDetection.floorDistance < 0; // On calcule l'angle d u sol _slopeAngle = Vector3.Angle(_floorDetection.hitNormal, transform.up) * Mathf.Deg2Rad; // On calcule la friction float staticFriction = _floorDetection.collider.material.staticFriction; // On determine si on est en train de glisser en fonction de l'angle et de la static friction _isSliding = _isOnGround && staticFriction < Mathf.Tan(_slopeAngle); } // On calcule la ground Correction _groundCorrection = Vector3.zero; if (_isOnGround) { _groundCorrection = (-_floorDetection.floorDistance / Time.fixedDeltaTime) * transform.up; } }
private void handleGround() { // On genere les infos du sol _floorSensor.Cast(); _floorDetection = _floorSensor.GetFloorDetection(); Debug.Log("test"); if (_floorDetection.detectGround) { Debug.Log("test1"); if (_isOnGround) { if (_forceToAdd.y > 2f) { _isOnGround = false; } } else { if (_floorDetection.floorDistance < 0.1f) { _isOnGround = true; } } } else { Debug.Log("test2"); _isOnGround = false; } _animator.SetBool("isOnGround", _isOnGround); // On calcule la ground Correction _groundCorrection = Vector3.zero; if (_isOnGround) { _groundCorrection = (-_floorDetection.floorDistance / Time.fixedDeltaTime) * transform.up; } }
public void Cast() { Vector3 wordOffset = _owner.TransformVector(_offset); Vector3 originPosition = _owner.position + wordOffset; RaycastHit hit; _lastDetection = new FloorDetection(); _lastDetection.detectGround = false; if (_debugMode) { Debug.DrawRay(originPosition, _castDirection, Color.red, Time.fixedDeltaTime * 1.01f); } if (Physics.Raycast(originPosition, _castDirection, out hit, _castLength, _layermask)) { _lastDetection.detectGround = true; _lastDetection.hitDistance = hit.distance; _lastDetection.floorDistance = hit.distance + Vector3.Dot(wordOffset, _castDirection); _lastDetection.hitNormal = hit.normal; _lastDetection.collider = hit.collider; } }