Hello boys, girls and David Baszucki himself. So, I’m making a classic Sonic game and Sonic never collides with a part. I have a part called “BottomHitbox” which I’m using to detect collisions at his feet. If I shouldn’t do this, how do I check if a part was touched on a certain face?
Here is the main script for Sonic:
local speedX = script.Parent.Variables.speedX.Value
local speedY = script.Parent.Variables.speedY.Value
local falling = script.Parent.Variables.falling.Value
local bottomCollisions = script.Parent.Variables.bottomCollisions.Value
wait(10)
--GAME LOOP
repeat
--HANDLING COLLISIONS
script.Parent.BottomHitbox.Touched:Connect(function(part)
print(part.Name)
if part.Name == "Solid" then
bottomCollisions = true
end
end)
script.Parent.BottomHitbox.TouchEnded:Connect(function()
bottomCollisions = false
end)
--GRAVITY
if bottomCollisions == false then
falling = 1
elseif bottomCollisions == true then
falling = 0
end
if falling > 0 then
speedY = speedY - 0.1
elseif falling < 1 then
speedY = 0
end
--MOVING SONIC
script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0, speedY, 0)
--script.Parent.BottomHitbox.Position = script.Parent.BottomHitbox.Position + Vector3.new(0, speedY, 0)
wait(0.01)
until false
Here’s the explorer:
Oh and before I forget, here’s it happening:
Thank you!
-Titanic (6 months ago, now Randomosity)
(also can you tell me why i can not set my display name to titanic thnx)
The first thing I would try is to make the bottom collision part thicker to avoid it clipping through the floor. The .Touched events are known to have a slight delay varying at times, making it update to bottomCollisions = true too late.
Either that or you can look into creating a new jump mechanic to move the part’s velocity when pressing spacebar, not having to disable collision at all.
If that does not provide clarity, I suggest you get rid of the command bar and enable the output when you go to ‘View’ at the top of your screen. Then you can show any errors or prints that come through.
I’ll try your first suggestion, which might not work because the part to collide with is very tall (since we’re working with the Y axis). But the output window, I already checked in there it’s just not printing anything.
It used to be speedY, falling, bottomCollisions- all the things in the script but now there’s only speedX. Also, I used Scratch too much that I forgot they are called Values instead of Variables. Also also, using the linear velocity:
(hope i didnt leak anything confidential) See how those 2 lines are being drawn on either side of Sonic? Using Velocity doesn’t give the same effect, so I need multiple anchor points. Let’s try that.
(If you want to use this lua script to add an overlay to the ROM, you can get it here.)
I changed them from CFrame to Position but Sonic still clips through the floor (did I mention that? he lands but clips a little bit into the floor (most likely because i’m moving Sonic by speedY which keeps getting bigger but I don’t know how to fix that)) and now the camera and side bars don’t follow Sonic.