I want my skateboards to be able to roll up and down ramps smoothly but the board kind of flys out sideways. I am using a PID controller to keep the board upright based on the normals on a part.
Ive tried making the value a negative but that just doesnt work. Heres my code, thanks for any help in advance.
rs.Heartbeat:Connect(function(dt)
local orientZ = hrp.Orientation.Z
local orientX = hrp.Orientation.X
local balanceForceZ = bpidZ:Calculate(hnZ,orientZ,dt)
local balanceForceX = bpidX:Calculate(-hnX,orientX,dt)
vf.Force = Vector3.new(-balanceForceZ,0,balanceForceX)*75
end)
im using a ray to see the part beneath the boards normal, then *ing by 100 to get an angle, my understanding is that its trying to get it to that angle even if youre like facing away. like for example when you face the ramp the ramp might be like 15 degrees but when you face away you should be, 345??? maybe? I dont know how i would program that ._.
rs.Heartbeat:Connect(function(dt)
local orientZ = hrp.Orientation.Z
local orientX = hrp.Orientation.X
local balanceForceZ = bpidZ:Calculate(hnZ*100,orientZ,dt)
local balanceForceX = bpidX:Calculate(hnX*100,orientX,dt)
vf.Force = Vector3.new(-balanceForceZ,0,balanceForceX)*75
end)
It would be 165 degrees at the bottom of the hill, and I believe 195 degrees at the top(?) This is some weird mathin 3D space, but 2 vectors pointing towards each other is 180 degrees in 2D space.
I found math for the “angle between 2 vectors” on this forum somewhere. I was using it find whether 2 models could see each other, but I’m certain its the same formula here. Check this thread out that talks about it in detail. If this isn’t working for you, I can dig through my game tomorrow and see what worked for me.
The angle should tell you when the board is not flush with the ground, which is what I thought you were trying to fix in the second video. It’s looking a lot better!
Lol, your force equation is above my head, but the solution I linked would potentially replace your ray (since that’s what this one does as well), and fix the tilt.
I would scrap using the humanoids orientation alltogether, because no matter how much you doctor it up its still the wrong angle at the end of the day
Ill be going with an angle approach like @GolgiToad described
Instead of humanoid.Orientation.X, try:
local dotX = skateboardlookvector:Dot(normalVector)
local orientX = (math.deg(math.acos(dotX))-90)*math.sign(dotX)
Instead of humanoid.Orientation.Z, try:
local dotZ = skateboardrightvector:Dot(normalVector)
local orientZ = (math.deg(math.acos(dotZ))-90)*math.sign(dotZ)
I highly doubt this will work first try but hopefully it will set you on the right track
Some basic troubleshooting would be making sure the look vector of the skateboard is actually forwards and that the right vector of the skateboard is actually facing right
Also you might want to mess with the first argument of your PID, I have no clue what it does but it might have undesired effects
Yes, simply take your original code and replace the humanoid angles with those calculated angles
You might have to mess with the first argument of the pid