public static void DelegatedSteer(CharacterSteeringMotor motor, Vector3 targetDirection, float targetRange, float outerRange) { Transform transform = motor.transform; float angle = Vector3.Angle(targetDirection, transform.forward); Vector3 cross = Vector3.Cross(targetDirection, transform.forward); float deltaAngle = angle * cross.y < 0 ? 1 : -1; // Maybe? // If we're within targetRange, we don't need to adjust. if (angle < targetRange) { return; } // If we're outside the slowdown range, we want maximum turning. // Assume we are. float targetRotation = motor.maxRotation; if (angle < outerRange) { targetRotation *= angle / outerRange; } targetRotation *= angle / deltaAngle; float adjustment = targetRotation - motor.rotation; motor.Steer(adjustment); }
// Update is called once per frame void Update() { if (target != null) { steeringMotor.Steer(transform.position - target.position); } }
// Update is called once per frame void Update() { Vector3 newTargetPosition = target.position; Vector3 targetVelocity = (newTargetPosition - lastTargetPosition) / Time.deltaTime; steeringMotor.Steer(targetVelocity); lastTargetPosition = newTargetPosition; }
// Update is called once per frame void Update() { // We want velocity 0 at inner radius-, and velocity full at outerRadius+ Vector3 currentVelocity = steeringMotor.velocity; float targetSpeedFactor = (Mathf.Clamp(Vector3.Distance(transform.position, target.position), innerRadius, outerRadius) - innerRadius) / (outerRadius - innerRadius); float targetSpeed = steeringMotor.maxSpeed * targetSpeedFactor; Vector3 targetVelocity = target.position - transform.position; targetVelocity = targetVelocity.normalized * targetSpeed; steeringMotor.Steer(targetVelocity - currentVelocity); }
public static void DelegatedSteer(CharacterSteeringMotor motor, Vector3 destination) { motor.Steer(motor.transform.position - destination); }
public static void DelegatedSteer(CharacterSteeringMotor motor, Transform delegatedTarget) { motor.Steer(motor.transform.position - delegatedTarget.position); }