Good morning (or night (or evening (or afternoon (or noon whichever))))!
So, I’m recreating Geometry Dash, a 2D platformer/rhythm game, in Roblox.
I’ve got the movement of the cube in check (deactivated in the video shown later), and jumping is fine but it’s falling that’s going wrong.
HALF OF THE TIME, I land perfectly on the ground where I started the jump.
THE OTHER HALF OF THE TIME, I fall into the ground (usually 2 blocks down for some reason).
Here’s a video of that happening:
robloxapp-20240121-1407205.wmv (2.2 MB)
(For context, one block/unit is 2 studs.)
Here is the movement script (placed inside the yellow block):
local ts = game:GetService("TweenService")
local gameValues = game.ReplicatedStorage.Values
local speedValues = {
slow = 8.6, --0, Slow
normal = 10.4, --1, Normal
fast = 12.96, --2, Fast
faster = 15.6, --3, Faster
fastest = 19.27 --4, Fastest
}
--TWEENS--
local jumpTween = ts:Create(script.Parent, TweenInfo.new(0.25, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {
CFrame = script.Parent.CFrame + Vector3.new(0, 4, 0)})
local fallTween = ts:Create(script.Parent, TweenInfo.new(0.25, Enum.EasingStyle.Sine, Enum.EasingDirection.In), {
CFrame = script.Parent.CFrame - Vector3.new(0, 4, 0)})
--GET ATTRIBUTES--
local currentSpeed = script.Parent:GetAttribute("Speed")
--MOVEMENT--
game:GetService("RunService").Heartbeat:Connect(function()
--MOVEMENT--
--script.Parent.Position += Vector3.new(0,0,(-0.05 * speedValues[currentSpeed]))
--GROUND CHECKING--
local raycast = workspace:Raycast(Vector3.new(script.Parent.Position.X, script.Parent.Position.Y - (script.Parent.Size.Y / 2) ,script.Parent.Position.Z), script.Parent.CFrame.LookVector * 0.25)
if raycast then
if raycast.Instance then
script.Parent:SetAttribute("Grounded", true)
jumpTween:Pause()
fallTween:Pause()
end
end
--JUMPING--
if gameValues.Clicking.Value == true then
if script.Parent:GetAttribute("Grounded") == true then
script.Parent:SetAttribute("Grounded", false)
jumpTween:Play()
jumpTween.Completed:Connect(function()
fallTween:Play()
end)
end
end
end)
Thank you for any help you can give!