How can I move an object on a non flat surface in vulkan?

I am writing a small "game" in vulkan, in which a car can move in an environment that is not flat, like a desert with valleys.

I am able to translate my car and follow it with the camera on a flat horizontal plane, however I can't figure out how can I understand if there is a downhill or an uphill and rotate my car consequently.

I was thinking to create a sort of matrix in which for each point I have the eight in thet point and so I can add an offset to the car, and rotate it approximating a plan with the neares points, but I have an obj file, and I don't know how I can proceed.

EDIT: I am developing a 3d app, in which the car moves in a terrain like the one I link here: https://3dmdb.com/en/3d-model/cycles-mountain-shader-vol-1/1031398/?free=True&q=mountains+displacement

I have created a displacement map with blender of the terrain, in this way I can understand how height I am with respect to the zero, while moving on the map.

I read the corresponding pixel of the height map, which changes from 0 to 255, and I retrieve if I am "high" or "low".

I would like to know if my idea is correct and, moreover, how can I increase the precision; in fact even with the height map I can't be precise, since let's say the value 125 doesn't mean that I'm exacly at half of the total height, for may experiance trying this option, at least.

Thanks

• Depending on where you want to go with this, you could rely on a physics engine to do those calculations. The physics engine controls the world in a realistic way, and your own graphics engine displays it. Jul 1, 2022 at 13:43
• I must use just vulkan, for a university project. I was thinking to use height maps, but they doesn't seem too precise Jul 3, 2022 at 8:38
• I suggest you edit the question and tell us a bit more about what you have so far (including if it's 2d or 3d), that would help us help you. Jul 3, 2022 at 12:53
• Ok, I have update the quastion with how I am proceeding, if you can help it would be great Jul 3, 2022 at 16:01
• Do you have a mesh for your terrain? How do you currently move your car? Jul 3, 2022 at 16:38