/// <summary> /// Gets the desired steering output. /// </summary> /// <param name="input">The steering input containing relevant information to use when calculating the steering output.</param> /// <param name="output">The steering output to be populated.</param> public override void GetDesiredSteering(SteeringInput input, SteeringOutput output) { if (!_jumping) { if (!_unit.isGrounded) { return; } var scanPoint = _unit.position + (_unit.forward * this.scanDistance); var unitElevation = _unit.position.y; _targetHeight = _heightSampler.SampleHeight(scanPoint) + _unit.baseToPositionOffset; if (_targetHeight - unitElevation < this.minimumHeightToJump || ((_targetHeight - unitElevation) - _unit.heightNavigationCapability.maxClimbHeight) > 0.0001f) { return; } var halfDistance = this.scanDistance / 2f; var speed = _unit.velocity.magnitude; var timeToTarget = halfDistance / speed; //Calculate the distance the unit will drop due to gravity and adjust the target height accordingly //Since gravity is assumed negative we do -0.5 instead of just 0.5 var drop = -0.5f * input.gravity * timeToTarget * timeToTarget; _targetHeight += drop; _force = _targetHeight / (Time.fixedDeltaTime * timeToTarget); } _jumping = _unit.position.y < _targetHeight; output.overrideHeightNavigation = true; output.verticalForce = _force; }