Character keeps glitching when on ramp

0.00031119220102599, -0.00027016352285646, -0.015008091107112  -  Client - BoardLogic:415
  02:01:50.750  0.016667468029498, 0.00031315863194849, -0.00030375616403611, -0.015011350406995  -  Client - BoardLogic:415
  02:01:50.764  0.016667389655748, 0.00031217325391348, -0.00026683776172948, -0.014999527777295  -  Client - BoardLogic:415
  02:01:50.782  0.016667094503537, 0.00031239500891642, -0.0002836266881611, -0.01499709595364  -  Client - BoardLogic:415
  02:01:50.795  0.016666956098829, 0.00030563743491853, -0.00017080571938391, -0.014998124932857  -  Client - BoardLogic:415
  02:01:50.814  0.016667149531916, 0.00031341928722394, -0.00036423214351606, -0.015002476695825  -  Client - BoardLogic:415
  02:01:50.828  0.016668441865039, 0.00030803945509483, -0.00020780290876112, -0.015018276646903  -  Client - BoardLogic:415
  02:01:50.847  0.016669424038213, 0.00031139902645347, -0.00031751857638513, -0.015013374462937  -  Client - BoardLogic:415
  02:01:50.862  0.016670086046278, 0.00031038016760789, -0.00026481397462434, -0.01501251718874  -  Client - BoardLogic:415
  02:01:50.880  0.01667052293825, 0.00031557946391097, -0.00033864961899936, -0.015008060992348  -  Client - BoardLogic:415
  02:01:50.896  0.016670764729608, 0.00031546729668178, -0.00028252107272356, -0.015006705052446  -  Client - BoardLogic:415
  02:01:50.913  0.01667040954644, 0.00030927029827878, -0.00020961522446321, -0.014999429419504  -  Client - BoardLogic:415
  02:01:50.935  0.016669815906967, 0.00030771960261968, -0.00026177584101911, -0.014997026226135  -  Client - BoardLogic:415
  02:01:50.949  0.016670863113678, 0.00031096390619157, -0.0003263617710978, -0.015018784367221  -  Client - BoardLogic:415
  02:01:50.968  0.016672050392625, 0.00030640840549036, -0.00022766277053153, -0.015017382682057  -  Client - BoardLogic:415
  02:01:50.985  0.016658466720851, 0.00032281012045945, -0.00048410274326774, -0.014832305061888  -  Client - BoardLogic:415
  02:01:51.013  0.016642485145807, 0.00028663007912356, 1.2818013918822e-06, -0.014863720307875  -  Client - BoardLogic:415
  02:01:51.030  0.016641634707235, 0.00029353911144976, -0.00034308319163054, -0.014967759616722  -  Client - BoardLogic:415
  02:01:51.048  0.016644566219019, 0.00029038696478602, -0.0002263879057641, -0.015012622904925  -  Client - BoardLogic:415
  02:01:51.064  0.016646600601485, 0.00028251295557241, -0.00016179418064524, -0.015005831066938  -  Client - BoardLogic:415
  02:01:51.087  0.016646208732731, 0.0002879067792932, -0.00030806197729281, -0.014978031873873  -  Client - BoardLogic:415
  02:01:51.105  0.016646884081008, 0.00030725582174173, -0.00049112987944101, -0.014989685940065  -  Client - BoardLogic:415
  02:01:51.125  0.01665086946961, 0.00030859739912407, -0.000291129769498, -0.015025566112016  -  Client - BoardLogic:415
  02:01:51.146  0.016650791095859, 0.00030905034107813, -0.00028245125893169, -0.014984966915955  -  Client - BoardLogic:415
  02:01:51.161  0.016650044043937, 0.00031538337318695, -0.00036813315604426, -0.014975096913675  -  Client - BoardLogic:415
  02:01:51.183  0.016651029552164, 0.00032002000948669, -0.00033009321711993, -0.014994869602512  -  Client - BoardLogic:415
  02:01:51.208  0.01665366924679, 0.00031009554163537, -0.00019983345432259, -0.015009381788433  -  Client - BoardLogic:415
  02:01:51.228  0.016658541759549, 0.00031448970912331, -0.00032583033207237, -0.015040135215615  -  Client - BoardLogic:415
  02:01:51.251  0.016660306002703, 0.00031085353676466, -0.0002466254702234, -0.015010355994477  -  Client - BoardLogic:415
  02:01:51.272  0.016656038802105, 0.00031172880592382, -0.0002889136611711, -0.01494968844408  -  Client - BoardLogic:415
  02:01:51.285  0.01665388102267, 0.00030446604948533, -0.00016999396315188, -0.014957586742238  -  Client - BoardLogic:415
  02:01:51.310  0.016653649236471, 0.00031071408984001, -0.00033184608985827, -0.014986347700853  -  Client - BoardLogic:415
  02:01:51.325  0.016655605245186, 0.00031614551107801, -0.00035495242107986, -0.015015405484568  -  Client - BoardLogic:415
  02:01:51.346  0.016658450045585, 0.00031903525677422, -0.00031460778253463, -0.015019653747143  -  Client - BoardLogic:415
  02:01:51.361  0.016659907463843, 0.00032622688277466, -0.00038933458881352, -0.015013316951083  -  Client - BoardLogic:415
  02:01:51.382  0.016659458899185, 0.00032168732779803, -0.00024635595748694, -0.014989248002264  -  Client - BoardLogic:415
  02:01:51.398  0.016657092678923, 0.0003200612286636, -0.0002689560417594, -0.014963591383261  -  Client - BoardLogic:415
  02:01:51.422  0.016657534573475, 0.00032248357182219, -0.00031125034951409, -0.014995614789973  -  Client - BoardLogic:415
  02:01:51.441  0.016659032012372, 0.00031195386992515, -0.00017011811169441, -0.0150088630833  -  Client - BoardLogic:415
  02:01:51.455  0.016659995842754, 0.000311926668395, -0.00028034610455141, -0.015007740592542  -  Client - BoardLogic:415
  02:01:51.476  0.016662368733121, 0.0003115085360619, -0.00027656329033037, -0.015017664938724  -  Client - BoardLogic:415
  02:01:51.490  0.016659735708602, 0.00033776517780568, -0.00070721322025173, -0.014953326648537  -  Client - BoardLogic:415
  02:01:51.509  0.016650255819817, 0.00031327137239, -3.7445059161518e-05, -0.014890601209917  -  Client - BoardLogic:415
  02:01:51.532  0.016641377908137, 0.00029219844599611, -7.5480766883061e-05, -0.014898248278041  -  Client - BoardLogic:415
  02:01:51.547  0.016639510278332, 0.00027836149139221, -5.2255990135036e-05, -0.014948798033018  -  Client - BoardLogic:415
  02:01:51.567  0.016641104433773, 0.00026855494894832, -0.00014333707382382, -0.014992983818054  -  Client - BoardLogic:415
  02:01:51.582  0.016644386126144, 0.00027085597953571, -0.00027454369397054, -0.015023835910783  -  Client - BoardLogic:415
  02:01:51.601  0.016646222072944, 0.00027256858162042, -0.0002633937030998, -0.015000984142326  -  Client - BoardLogic:415
  02:01:51.617  0.01664613536156, 0.00028724125373334, -0.00043676567425377, -0.014980468426408  -  Client - BoardLogic:415
  02:01:51.636  0.016657127696982, 0.00031414713659616, -0.00056537425239755, -0.015106887584681  -  Client - BoardLogic:415
  02:01:51.652  0.016652967218087, 0.00030935930251918, -0.00022221086820978, -0.014938823578649  -  Client - BoardLogic:415
  02:01:51.669  0.016654484667303, 0.00031870201197484, -0.00040337734347051, -0.015007965605163  -  Client - BoardLogic:415
  02:01:51.692  0.016653524171975, 0.00031341144463719, -0.00023807221677206, -0.014980183962381  -  Client - BoardLogic:415
  02:01:51.706  0.016655778667954, 0.00031507594899712, -0.00030729845937365, -0.015022342156989  -  Client - BoardLogic:415
  02:01:51.726  0.016659950819535, 0.00030678484965466, -0.00019086369976231, -0.015036850570292  -  Client - BoardLogic:415
  02:01:51.742  0.016653370759527, 0.00029799221558636, -0.00015057537892518, -0.014900013306588  -  Client - BoardLogic:415
  02:01:51.760  0.016658061511884, 0.00029381904750328, -0.00021791732537507, -0.015044544877604  -  Client - BoardLogic:415
  02:01:51.777  0.016654211192939, 0.00030081632847181, -0.0003533242305622, -0.014943344413752  -  Client - BoardLogic:415
  02:01:51.790  0.016659338837269, 0.00031320560930371, -0.00047311123921292, -0.015072549167517  -  Client - BoardLogic:415
  02:01:51.807  0.016663345903715, 0.00031623214430381, -0.00031834681262567, -0.015041679535571  -  Client - BoardLogic:415
  02:01:51.820  0.016663279202651, 0.00030954658661754, -0.00017961857663294, -0.014995963836283  -  Client - BoardLogic:415
  02:01:51.838  0.016663677741511, 0.00031400396379142, -0.00033493831465488, -0.015001989273081  -  Client - BoardLogic:415
  02:01:51.852  0.016661054722152, 0.0003150668557653, -0.00029871394328081, -0.014957552561312  -  Client - BoardLogic:415
  02:01:51.872  0.016661561650241, 0.00031230605678623, -0.00025352273334918, -0.015000464617261  -  Client - BoardLogic:415
  02:01:51.891  0.016659117056229, 0.00031125306575244, -0.00026906583366028, -0.014967524299189  -  Client - BoardLogic:415
  02:01:51.905  0.01666591722975, 0.00031451240312021, -0.00032952991044696, -0.015096276362598  -  Client - BoardLogic:415
  02:01:51.924  0.016663254189752, 0.0003156535125208, -0.0002960853202437, -0.014968930654035  -  Client - BoardLogic:415
  02:01:51.938  0.016664928386469, 0.00031943642723364, -0.00033783770495708, -0.015020716594835  -  Client - BoardLogic:415
  02:01:51.958  0.016664114633483, 0.00033404677553408, -0.00045414878771985, -0.014989153303656  -  Client - BoardLogic:415
  02:01:51.972  0.016666090652517, 0.00033135650772561, -0.00026241742783047, -0.015025779436578  -  Client - BoardLogic:415
  02:01:51.990  0.016665351938229, 0.00032504781108534, -0.00021846130500297, -0.014990142174698  -  Client - BoardLogic:415
  02:01:52.006  0.016657799710207, 0.00034398445332384, -0.00053195509660586, -0.014903335481378  -  Client - BoardLogic:415
  02:01:52.026  0.016646502217414, 0.0003142528942694, 3.8253368983373e-05, -0.014859846621491  -  Client - BoardLogic:415
  02:01:52.040  0.016642575192244, 0.0003104664100071, -0.00022517400048048, -0.014922058493365  -  Client - BoardLogic:415
  02:01:52.059  0.016645723482487, 0.00029943624164354, -0.00015305688190408, -0.015014384850906  -  Client - BoardLogic:415
  02:01:52.076  0.016647267612129, 0.0002820057929438, -4.8160587062214e-05, -0.015000758509517  -  Client - BoardLogic:415
  02:01:52.091  0.016645513374134, 0.00027325294502156, -0.00012889262340076, -0.014957505980683  -  Client - BoardLogic:415
  02:01:52.108  0.016643250540522, 0.00027665613262683, -0.00028914136437951, -0.014952228550485  -  Client - BoardLogic:415
  02:01:52.122  0.016643255543102, 0.00027877873785173, -0.0002802104957928, -0.014978999066061  -  Client - BoardLogic:415
  02:01:52.140  0.016646847395423, 0.00030208026163976, -0.00053023136089115, -0.015021987854986  -  Client - BoardLogic:415
  02:01:52.154  0.016650079061996, 0.00030217148056412, -0.00027325470840876, -0.015031140338928  -  Client - BoardLogic:415
  02:01:52.171  0.016649635499917, 0.00030030153169729, -0.00024831843294934, -0.014979464591401  -  Client - BoardLogic:415
  02:01:52.184  0.016648383187432, 0.00030456414695755, -0.00033954795800331, -0.014964319203991  -  Client - BoardLogic:415
  02:01:52.200  0.0166499539975, 0.00031233002748329, -0.0003722674067558, -0.015003399694481  -  Client - BoardLogic:415
  02:01:52.221  0.0166511696244, 0.0003074957371532, -0.00022706845807698, -0.014998544579248  -  Client - BoardLogic:415
  02:01:52.235  0.016652150130047, 0.00031326181016628, -0.00036458953877486, -0.015000990198376  -  Client - BoardLogic:415
  02:01:52.253  0.016653877687617, 0.00031556406534361, -0.00030832472454959, -0.015006736867064  -  Client - BoardLogic:415
  02:01:52.266  0.01665468310297, 0.00031638203932577, -0.00029737104572942, -0.015001648133214  -  Client - BoardLogic:415
  02:01:52.287  0.016654169504774, 0.00031652591561835, -0.00028631700275283, -0.014983599024405  -  Client - BoardLogic:415
  02:01:52.313  0.016653215679552, 0.00030789748082495, -0.00021050838888441, -0.014980531926514  -  Client - BoardLogic:415
  02:01:52.331  0.016653579200353, 0.00031034507138077, -0.00030570386388194, -0.014992141263344  -  Client - BoardLogic:415
  02:01:52.349  0.016655978771147, 0.00031404750187272, -0.0003237034707025, -0.015016992629846  -  Client - BoardLogic:415
  02:01:52.364  0.016657417846613, 0.00031669840041678, -0.00032030737462929, -0.015010827634598  -  Client - BoardLogic:415
  02:01:52.381  0.016662865656051, 0.00031396852884794, -0.00025051596651386, -0.015060550377045  -  Client - BoardLogic:415
  02:01:52.397  0.016666876057551, 0.00031096278582203, -0.0002445713577473, -0.015047280874283  -  Client - BoardLogic:415
  02:01:52.412  0.016659095378383, 0.00031275675800122, -0.00030706103726409,

It doesnt even look like its doing anything, weird
Does it fling the board positionally or rotationally?

rotationally i dunno what ur tryna do

local rs = game:GetService("RunService")

local p = script.Parent

local vf = p.vf

local kp = 0.5
local ki = 0.5
local kd = 0.5

local last_x = 0
local I_x = 0
function pid_x(dt, x)
	local P = kp * x
	I_x = I_x + x * dt
	local I = ki * I_x
	local D = kd * math.clamp((x - last_x)/dt, -500, 500)
	last_x = x
	return P + I + D,P,I,D
end

local last_z = 0
local I_z = 0
function pid_z(dt, z)
	local P = kp * z
	I_z = I_z + z * dt
	local I = ki * I_z
	local D = kd * math.clamp((z - last_z)/dt, -500, 500)
	last_z = z
	return P + I + D
end

function update(dt)
	local lookVector = p.CFrame.LookVector
	local rightVector = p.CFrame.RightVector
	local upVector = p.CFrame.UpVector
	local normalVector = Vector3.new(0, 1, 0)

	local dotX = lookVector:Dot(normalVector) 
	local dotY = upVector:Dot(normalVector)
	local dotZ = rightVector:Dot(normalVector) 

	local orientX = math.deg( math.atan2(dotX, dotY) )
	local orientZ = math.deg( math.atan2(dotZ, dotY) )

	vf.Force = Vector3.new(pid_x(dt, orientX), 0, pid_z(dt, orientZ))
end

while true do
	local dt = rs.Heartbeat:Wait()
	update(dt)
end

I got it to work fairly nicely with a custom PID implementation (dont judge the code its horrible)


You can see how it kinda launches when you go too far over, you can fix this by clamping the D value like I did in the code to lower values, 200 works nicely for me but then again my version is way slower than yours

Its really finnicky and really just a proof of concept but should offer validation to this way of going about it

Fixed PID:


With mitigated flinging:

So how do you implement a raycast normal to be the set point?

For my example, the set point is 0
The math equation should handle making the “center point” the normal vector, while you just have to worry about if what the equitation spits out is equal to 0 in both axes
If it is, you can guarantee its upright relative to normalVector

All the equation does is find the upright angle to the normal vector, you can see why youd want the set point to be 0 degrees
image

1 Like


i dunno it doesnt even stay upright

with a set point of zero it will try and go perfectly flat instead of adhering to the surface normal

Are you sure youre getting and applying the normal correctly?

yeah im pretty sure i am, where in the script does it calculate how to rotate properly on the normal?

The :Dot is where the normal is accounted for
Are you sure you didnt leave in a normal = Vector3.new(0,1,0) anywhere or anything?
Or could you just show the code?

its your exact code, i dont really see why you remade the pid function

local rs = game:GetService("RunService")
local kp = 0.5
local ki = 0.5
local kd = 0.5

local last_x = 0
local I_x = 0
function pid_x(dt, x)
	local P = kp * x
	I_x = I_x + x * dt
	local I = ki * I_x
	local D = kd * math.clamp((x - last_x)/dt, -500, 500)
	last_x = x
	return P + I + D,P,I,D
end

local last_z = 0
local I_z = 0
function pid_z(dt, z)
	local P = kp * z
	I_z = I_z + z * dt
	local I = ki * I_z
	local D = kd * math.clamp((z - last_z)/dt, -500, 500)
	last_z = z
	return P + I + D
end

rs.Heartbeat:Connect(function(dt)
	local lookVector = Board.CFrame.LookVector
	local rightVector = Board.CFrame.RightVector
	local upVector = Board.CFrame.UpVector
	local normalVector = Vector3.new(0, 1, 0)

	local dotX = lookVector:Dot(normalVector) 
	local dotY = upVector:Dot(normalVector)
	local dotZ = rightVector:Dot(normalVector) 

	local orientX = math.deg( math.atan2(dotX, dotY) )
	local orientZ = math.deg( math.atan2(dotZ, dotY) )

	vf.Force = Vector3.new(pid_x(dt, orientX), 0, pid_z(dt, orientZ))
end)

Oh that was just a proof of concept
I remade the PID code cause I didnt have your full PID module
That code was hard coded to face upwards, to fix it youd just have to replace

local normalVector = Vector3.new(0, 1, 0)

With a raycast downwards and the return value of that normal vector

You could also just use your PID and my math if you can figure out what its problem was when you made the goal 0

with your math is the outcome of it an angle?

Yes, my math could be simplified to just inputting into your PID

its not working :\ idk it works when the set point is 0 but not with ur maths

if your math is based off the normal vector it should just be exactly 0 if the hit par was flat but it varies alot and isnt stable

What do you mean simplified how do i make it work

Whats your current code?
Does it raycast to get the normal vector?

yes its raycasting to get the normal vector but im printing the value your math is spitting out and it gives me stuff like 0, 3 or -0.5 , .1 stuff like that but if its off the raycast shouldnt it be stuff like 0, 0 or if its on a ramp like 15,0 and depending on angle other stuff?