Hey fam,
I’m trying to make a game where a car has to go over hills. I want the car to accelerate as it goes down the hill, but I never want the car to come off the hill at any point.
Does anyone know a good method to achieve this?
Here is an example:
One way that games do this is to modify the physics gravity vector depending on where the player is (Unity - Scripting API: Physics.gravity). For example, if the player does a raycast downwards to find the ground (and they’re standing on it) they can change the physics gravity vector to be the inverse of the ground normal.
For example, if the player raycasts and finds himself on a slope of 45 degrees then the 2d normal of that face would be (0.707,0.707). You could then mirror that to create the gravity vector needed to make the player stick to that slope (-0.707,-0.707)