# Slopes and wind direction

Hi there;

I’m tearing my head out with a problem with my project and I just can’t get my head around it. Basically I’m trying to work out the angle difference between a slope and a given wind direction.

I hoped that I could calculate a normal from 3 points in space as per http://docs.unity3d.com/Manual/ComputingNormalPerpendicularVector.html . Then do a bit of maths to work out the difference between the angles. My efforts have only produced pain.

I’ve been using raycast Normals to find out the normal, then converting the resulting normal to a Vector2, and working out the difference between my wind direction and the equivalent angle component for the normal. That’s the best way to describe it.

This is for a gliding flight simulator, and to simulate ridge lift I need to work out how ‘on slope’ the wind is. If the wind is on the slope (i.e. westerly wind and a hill slope facing west also, then there is no difference. If the wind is South-westerly, that is 225’ and the slope is still West facing, then there is a 45’ difference … if the wind was East, and the slope faces west, then the difference would be 180’). I hope those examples help.

I hope this makes sense. I suspect there is a way of doing it with Normals and my wind direction, but it’s driving me crackers.

Can anyone point me in the right direction?

Many thanks;

Graeme

Okay, I’m gonna explain how I get my character to maintain its speed on a slope, cause the problem sounds similar, figuring out the relative movement of an object to a slope.

I cross product the collision normal to my input, but the forward of my input is rightward instead. Meaning for my input, forward goes right, right goes backward, backward goes left, left goes forward. Looks something like this

So imagine the red Vector B is the slope normal, and blue Vector A is my rightward input. The purple Vector would be the result going forward. Ignore the “bxa = -axb” for now.

How this would apply to your situation is, having your rightward going wind cross product with your slope normal to get the “ridge lift” direction, and multiplying it by your wind speed.

The function in Unity is Vector3.Cross(a, b)

1 Like

That’s great thank you for the reply. I had been doing something wrong with Normals, so that was part of the problem. I had been doing something wrong with position and localposition, and because of that it was screwing up and I couldn’t see the error. Typically I woke up fresh faced, looked at it again, tackled the problem differently and after the normals thing was resolved… all it took was a few bits of sohcahtoa trigonometry and it was fixed and working.

Basically ridge lift (it’s a bird flight simulator) only works well when the slope is within 30’ of a given wind direction, so I was comparing the slope with the wind, and working out the appropriate component. It seems to be working now, so I’m going to leave it alone!

The latest video for the simulator is here: