Hi. I want to make the player character a controllable ball that can roll. I did this. I actually implemented this as well as a jump script, but the movement feels very bad and janky, and you cant control the ball when its in the air.
I was wondering how I can fix my current code to make movement better.
Here is the code:
Main Marble Movement Script:
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local HRP = char:WaitForChild("HumanoidRootPart")
local marble = Instance.new("Part")
marble.Size = Vector3.new(8,10,8)
marble.Color = Color3.fromRGB(255, 160, 94)
marble.Transparency = 0
marble.Name = "Marble"
marble.Shape = Enum.PartType.Ball
marble.Parent = char
marble.Material = Enum.Material.SmoothPlastic
local Velocity = Instance.new("BodyAngularVelocity")
Velocity.Parent = marble
local Hum = char:WaitForChild("Humanoid")
local Weld = Instance.new("Weld")
Weld.Parent = marble
Weld.Part0 = HRP
Weld.Part1 = marble
Hum.PlatformStand = true
while true do
wait()
marble.BodyAngularVelocity.AngularVelocity = Vector3.new(char.Humanoid.MoveDirection.z * 32,0,char.Humanoid.MoveDirection.x * -32)
marble.BodyAngularVelocity.MaxTorque = Vector3.new(40000,40000,40000)
if char.Humanoid.MoveDirection == Vector3.new(0,0,0) then
marble.BodyAngularVelocity.MaxTorque = Vector3.new(0,0,0)
end
end
end)
end)
Marble Jump Script
local userInput = game:GetService("UserInputService")
local players = game:GetService("Players")
local player = players.LocalPlayer
local pressed = false
local function beginJump(input, gameProcessed)
if not gameProcessed then
if input.UserInputType == Enum.UserInputType.Keyboard then
local keycode = input.KeyCode
if keycode == Enum.KeyCode.Space then
if pressed == false then
game.Players.LocalPlayer.Character.Marble.AssemblyLinearVelocity = game.Players.LocalPlayer.Character.Marble.AssemblyLinearVelocity * Vector3.new(1, 0, 1) + Vector3.new(0, 75, 0)
pressed = true
wait(2)
pressed = false
end
end
end
end
end
userInput.InputBegan:Connect(beginJump)
Any help is appreciated!