# How would i detect if my vehicle is on a slope or not?

I am making a game based on MMX hilldash, but one problem, my car slows down on slopes that are bearly steep at all, and cause a lot of trouble with jumps. I want to know how to fix this, but I don’t know where to start.
What i mean is, when it goes off of the ramp, it immediately drops down. Footage:
robloxapp-20240614-1125250.wmv (708.1 KB)

Can’t you just constantly check your car’s rotation to know whether it’s driving up a slope?

1 Like

How are you moving the vehicle?
If you are using HingeConstraints on the wheels increase the Torque so the slope doesn’t slow the vehicle down as much. You may need to increase the wheel friction in case the wheels are spinning up the hill. You can put a decal on the wheels to see if they are spinning instead of getting traction. I usually start with Friction 2 on my wheels and tune them down if necessary.
The ‘falling’ gravity effect looks normal, but if you want vehicles to fall more slowly you could put a VectorForce in the car with the force pointing upwards on the global Y axis.

torque?
i am using hingeconstraints, but i am also using a velocity, i forgot what kind.

Firstly is that you should have a set PrimaryPart, at the position of the pivot of the whole model.

With a script, just detect the angle of that PrimaryPart, and set a range of angles (like if the PrimaryPart angle is from 0 to 50 degrees, then slow the car down), and do this in the Y axis.
This image is what i mean by ‘range’ of angles. Hope this helps! The black dot in the middle represents the PrimaryPart / the car model.

maybe raycast and use the normal vector of that result,
if its not orthogonal to the floor or anything (dot product)
then its a slope

Why use a Velocity or try to find the angle?
If you’re using Roblox gravity and physics then just work with those.

I have a bunch of vehicle models, cars, trains, with suspension, without suspension, boats etc. and in only one of those cases have I ever tried to worry about the angle (it was a boat that had to stay level).

If you post that model here I can give it a look.

1 Like

car.rbxm (18.2 KB)

There’s a whole lot to process here. I’m guessing this is a vehicle you got from the toolbox because it seems way more complex than it needs to be.

VehicleSeats can do all the work for you since the W and S inputs are automatic. You no longer need UserInputService to find out the forward backward inputs.
HingeConstraints will make the Wheels turn so you don’t need to add a BodyAngularVelocity and control them that way. Just set the Hinges to Motor and use the built in AngularVelocity that they have.
Why are there CylinderMeshes in the wheels when they are already Cylinder Parts?
You don’t need 16 Attachments, 4 SpringConstraints, and 4 PrismaticConstraints for your axle suspension. You can just use 4 Attachments, 2 Springs and 2 Prismatics.
The wheels were Massless, which makes them have way less traction than they need.
Your scripts use server and local scripts with Heartbeat checks and RemoteEvents. Pretty sure you don’t need all that. It also checks for A and D inputs for steering, which you don’t seem to be using.
I have 1 script that controls the forward and backward.
You can tune the Springs to get better suspension. The maxforce, stiffness and damping are the tuning properties.
You can speed up or slow down the car acceleration by going into the HIngeConstraints (children of the DriveScript) and changing the MotorMaxAcceleration Property.
You can speed up or slow down the car speed by going into the DriveScript and changing the value of the `speed` variable. I’ve got it at 20 for now.
I changed the wheels CustomPhysicalProperties Friction to 2 so it will climb slopes and keep traction.
Here’s both our cars:
your car and my car.rbxm (24.9 KB)

From your video it looks like you are trying to make a cart system. You may want to search forum posts about how to keep your cart on the tracks. Use the search term
cart track rails train @Scottifly

its not from the toolbox.
it was hand scripted, i was just starting.
i literally put a day into that thing…

1 Like

No worries, it’s how we all learn. The first times I started messing with Constraints it worked sometimes and not others. That’s why the forums are here.

This only shows how I would have done it. Doesn’t make it more right or wrong than your way or anyone else’s.
Plus you may have been adding things for other reasons that I’m not aware of, like having Values for checking things in other scripted items.