Hello everyone,
This game is “2D Basketball,” and I want to recreate the same movement system shown in the video. Can someone explain everything in detail on how to script it?
(I’ve already made the rotation and jumping system, but I’m stuck on the phase where the player has to land and continue the rotation.)
Client Script
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local JumpEvent = ReplicatedStorage:WaitForChild("JumpEvent")
character:WaitForChild("Right Leg")
character.PrimaryPart = character:FindFirstChild("Right Leg")
if character:FindFirstChild("Animate") then
character.Animate:Destroy()
end
local humanoid = character:WaitForChild("Humanoid")
local hrp = character:WaitForChild("HumanoidRootPart")
humanoid.WalkSpeed = 0
humanoid.JumpPower = 0
humanoid.JumpHeight = 0
humanoid:ChangeState(Enum.HumanoidStateType.Physics)
task.wait(0.1)
local base = character:GetPivot()
local t = 0
local speed = 3.7
local rotationConnection
rotationConnection = game:GetService("RunService").Heartbeat:Connect(function(deltaTime)
t = t + deltaTime * speed
local angle = 45 * math.cos(t)
local newCFrame = base * CFrame.Angles(math.rad(angle), 0, 0)
if character.PrimaryPart.CFrame ~= newCFrame then
character:PivotTo(newCFrame)
end
end)
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if not gameProcessed and input.KeyCode == Enum.KeyCode.Space then
rotationConnection:Disconnect()
character:PivotTo(character:GetPivot())
JumpEvent:FireServer(character:GetPivot())
end
end)
Server Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local JumpEvent = ReplicatedStorage:WaitForChild("JumpEvent")
JumpEvent.OnServerEvent:Connect(function(player, characterCFrame)
local character = player.Character
if character then
local humanoid = character:FindFirstChild("Humanoid")
local hrp = character:FindFirstChild("HumanoidRootPart")
if humanoid and hrp then
for _, force in ipairs(hrp:GetChildren()) do
if force:IsA("BodyVelocity") or force:IsA("BodyForce") then
force:Destroy()
end
end
local upDirection = characterCFrame.UpVector
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.Velocity = upDirection * 30
bodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bodyVelocity.Parent = hrp
game:GetService("Debris"):AddItem(bodyVelocity, 0.5)
end
end
end)