I'm applying forces to a Rigidbody rb. The forces come from points along a spline splineComputer. The code says "find spline point that is currently nearest to rb, and apply forces to rb toward that spline point's forward direction".
This works, but what is missing is that the forces are applied at a constant speed, whereas I would like the speed to change based on the angle of the spline path.
Since targetDirection is constantly returning a Vector3 forward direction of the nearest spline point, is there some way to say "based on angle of targetDirection, adjust speed to move faster or slow down? Or another approach to try?
public class SplineScript : MonoBehaviour { SplineSample sample; public SplineComputer splineComputer; Rigidbody rb; Vector3 targetDirection; Quaternion targetRotation; public float speed = 60f; void Start() { sample = new(); rb = GetComponent<Rigidbody>(); } void Update() { splineComputer.Project(transform.position, ref sample); targetDirection = sample.forward; targetRotation = Quaternion.LookRotation(new Vector3(targetDirection.x, 0, targetDirection.z)); } private void FixedUpdate() { rb.velocity = targetDirection.normalized * speed * Time.deltaTime; } } Overall purpose: Make rigidbodies who enter a River spline to naturally move with its current, even as river flows down slopes



