Distinguishing 'peaks' from 'valleys' in an almost sine wave scenario?

I need to be able to tell the difference via code whether the area a player is in is a peak or a trough, based on the last surface normal, and current surface normal.

Information I have available:

  • Last surface normal
  • Last part position
  • Current surface normal
  • Current part position
  • Character velocity ( just in case its useful here… )

Right now I compare the surface normal’s angle relative to directly upward. This was not in anticipation of this problem, it’s just what I already had been doing.

As you can see below, comparing the angles relative to up on both peaks and troughs will yield the same result.

I believe you will need to measure the change of the gradient in a similar manner to differentiation.

How to measure the change of slope? maybe a combination of finding the player’s movement direction in the XZ Plane and the surface normal similar to this thread, multiple raycasts in a line in front of the player.

Edit: May we know what the purpose of detecting troughs and peaks is though, maybe there are easier alternatives?

1 Like

For a peak, the vectors would diverge and for a trough they would converge.

To detect that, you could project the 2 vectors onto their shared plane and see if they intersect in front of the vectors or behind them. For example:

2 Likes