# Car rotation help?

i need the truck to rotate up when its going up a hill Flowlab Game Creator - New Game
@CodeAlpaca

1 Like

Whatâ€™s the link? Thereâ€™s no truck.

2 Likes

Yeah thereâ€™s no truck

There is no truck. But try it with Rotation enabled when you do make it.
I saw Pizza did this and it actually worked out surprisingly well for being completely physics based.

hey i re added the truck can you fix it @CodeAlpaca

yeahhh I think Ima let codealpaca do this

I typically prefer to explain things and then have the person who asked the question implement the solution for themselves because you learn more that way, however, itâ€™s kind of hard to explain this. Because Iâ€™m using a mostly physics-based solution, itâ€™s a lot more trial and error than a coding solution would be.

I changed the Truck (really a tank) to be a Capsule Shape

I added a Ramp object. Its collision shape is Polygon and idk why it looks weird in the image. The sprite is literally just moving along down 1 pixel. If you know graphing, the rise and run is 1. Make sure it extends into the ground, this is needed because Flowlab doesnâ€™t handle ramps well and this is just one of the tricks a lot of people use.

Just that causes the â€śtruckâ€ť to move up the ramp.
However, going down the ramp isnâ€™t as smooth.

It will pretty much always flip over like this. Problem here is that itâ€™s rotating too much while going down the hill, so how would one fix this? Well the problem is too much rotation, so what if we limit it?

This code prevents the â€śtruckâ€ť from flipping over, but there is another problem with it.
The truck keeps wanting to flip itself over, even if I were to set its rotation down to -10, so this causes it to get locked at the maximum angle.

This is the expression â€śA < (-45)? (-44) : A > 45? 44 : 0â€ť
*(Expression is basically saying 'Is A less than -45? If yes set rotation to -44, if not: Is A Greater Than 45? If yes, set rotation to 44, if not, output 0. And the filter stops 0 from setting the rotation.

Now whatâ€™s the solution to this? Not entirely sure, I canâ€™t just lock it at 0 that ruins the original prompt of rotating a car up a hill. And I canâ€™t go from -45 or 45-degree angle straight to 0.

I tried applying a downward force or setting X velocity to 0, but that didnâ€™t work. Setting X velocity to 0 would work, but you need to stop the movement, which would be kind of odd to just suddenly stop. Then again, I guess it can kind of make sense because if the wheels arenâ€™t making enough with the ground, then it doesnâ€™t have enough traction to move.
Maybe a solution to this while making this into a feature is to slightly lower the movement of the truck the more rotation it has.

2 Likes