Alright so me and a few friends are attempting to remake a game called crab game but on roblox, it was going quite well until we had to do the movement system, I’ve never scripted anything like it.
I dont really have any knowledge of physics, and this system seems quite challenging to do.
I’ve searched through the dev forum, I’ve unfortunately gone to chatgpt, and I’ve tried going to some dc servers
In one of the servers a very kind person gave me a formula:
while wait(0.1) do
local distanceMoved = currentPos - savedPos
local speedGain = distanceMoved * math.sin(slope) * factorOfIncreasePerStud
-- Or you could apply the energy theorem to get final velocity:
-- V_final = sqrt(V_initial^2 + g * distanceTraveled * math.sin(slope))
local vFinal = math.sqrt(vInitial^2 + g * distanceMoved * math.sin(slope))
local speedIncrease = vFinal - vInitial
currentSpeed = currentSpeed + speedIncrease
end
Unfortunately I’m not the smartest as i wasnt quite able to wrap my head around it lol, here is a reference to the type of system im trying to create:
Any help is appreciated! I can upload some more references if needed
How about you account for forces. I suggest you to research about this
Essentially, there are two main forces acting on the body, friction and the weight(mg). On this slope model we find the forces acting on the body from all directions . We use the angle of the slope which is the theta in this case. In your game friction can be used as dampener, the formula for friction is mg(friction coefficient). Depending on your preferences, you could change the friction coefficient. Well there more on YouTube. But again you could use energy, but the way you used it is incorrect. At the top of the slope the body only has potential energy and that energy turns into kinetic energy as you move downward. Calculating the acceleration and the final velocity is possible using SUVAT equations. Honestly if I keep on continuing this post will be a physics lesson. Pick one forces or energy, both works. Also use run service instead of while loop it may be bit smoother.
It is quite feasible, I forgot to include something called g in the formula is
“-game.workspace.Gravity”. There are lot of tutorials on forces make sure to watch some.