/// <summary> /// Execute action /// </summary> public override CharacterActionResult Execute(float deltaTime) { CharacterActionResult result = new CharacterActionResult(); result.velocity = Controller2D.BaseVelocity; _hit.FoundAnyHit = false; _verifyCollision = false; if (_moveAxis != Vector3.zero /*&& !snapToWall*/) { _direction = _moveAxis; } if (Controller2D.HitStatus.FoundAnyHit && !isExecuting) { if (((wallSlideLayers.value & 1 << Controller2D.HitStatus.HitCollider.gameObject.layer) == 1 << Controller2D.HitStatus.HitCollider.gameObject.layer)) { isExecuting = true; if (snapToWall) { _direction = (Controller2D.HitStatus.HitPoint - Controller2D.TransientPosition); } } } if (snapToWall || _moveAxis != Vector3.zero) { _verifyCollision = true; } if (isExecuting && _verifyCollision) { Vector2 targetMovementVelocity = Vector2.zero; RaycastHit2D closestSweepHit; if (Controller2D.CharacterCollisionsSweep(Controller2D.TransientPosition + _handPosCenterToBottom - Controller2D.CharacterTransformToCapsuleCenter, Controller2D.TransientRotation, _direction, 0.2f, out closestSweepHit, _internalCharacterHits, 0, _capHeight) > 0) { if ((!Controller2D.MustUnground)) { Controller2D.Gravity = Vector2.zero; if (snapToWall) { _direction = (closestSweepHit.point - Controller2D.TransientPosition); } result.velocity = (-Controller2D.CharacterUp * fallingSpeed) + (Controller2D.CharacterRight * result.velocity.x); _hit.FoundAnyHit = true; _hit.HitCollider = closestSweepHit.collider; _hit.HitNormal = closestSweepHit.normal; _hit.HitPoint = closestSweepHit.point; result.velocity = Vector3.ProjectOnPlane(result.velocity, _hit.HitNormal); targetMovementVelocity = result.velocity; // Smooth movement Velocity result.velocity = Vector2.Lerp(result.velocity, targetMovementVelocity, deltaTime); OnSlidingWall.Invoke(_hit); } else { if (_moveAxis != Vector3.zero) { _direction = _moveAxis; } Controller2D.Gravity = OriginalGravity; } } else { ExitExecute(deltaTime); } } else { ExitExecute(deltaTime); } return(result); }