You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I would like the player to controll the ball -
What is the issue? Include screenshots / videos if possible!
When using a normalised vector everything flickers and i am only able to move some times
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Nothing works I’ve tried recoding the entire thing but no luck
Here is the movement script
local PlayerBall:Part
game.Players.LocalPlayer.CharacterAdded:Connect(function(char)
wait()
workspace.CurrentCamera.CameraSubject = char.HumanoidRootPart
PlayerBall = workspace.PlayerBalls[game.Players.LocalPlayer.Name .. "'s ball"]
end)
local MaxRotoSpeed = 50
local MovementVector
game.Players.LocalPlayer.CharacterAdded:Wait()
wait(.2)
game["Run Service"].Heartbeat:Connect(function(dt)
local BV
local CheckSpeed = function()
BV = PlayerBall.AssemblyAngularVelocity
PlayerBall.AssemblyAngularVelocity = Vector3.new(math.clamp(BV.X,-MaxRotoSpeed,MaxRotoSpeed),math.clamp(BV.Y,-MaxRotoSpeed,MaxRotoSpeed),math.clamp(BV.Z,-MaxRotoSpeed,MaxRotoSpeed))
end
MovementVector = Vector3.new(0,0,0)
local Keys = game.UserInputService:GetKeysPressed()
for i=1, #Keys do
local CurrentKey:InputObject = Keys[i]
if (CurrentKey.KeyCode == Enum.KeyCode.W) then
if PlayerBall.Anchored then return end
MovementVector += workspace.CurrentCamera.CFrame.LookVector * Vector3.new(1,0,1)
elseif (CurrentKey.KeyCode == Enum.KeyCode.S) then
if PlayerBall.Anchored then return end
MovementVector -= workspace.CurrentCamera.CFrame.LookVector * Vector3.new(1,0,1)
elseif (CurrentKey.KeyCode == Enum.KeyCode.D) then
if PlayerBall.Anchored then return end
MovementVector += workspace.CurrentCamera.CFrame.RightVector * Vector3.new(1,0,1)
elseif (CurrentKey.KeyCode == Enum.KeyCode.A) then
if PlayerBall.Anchored then return end
MovementVector -= workspace.CurrentCamera.CFrame.RightVector * Vector3.new(1,0,1)
end
end
--Nomalised
MovementVector = MovementVector.Unit
local MaxSpeed = 50
local Speed = math.sqrt( math.pow(PlayerBall.AssemblyLinearVelocity.X,2) + math.pow(PlayerBall.AssemblyLinearVelocity.Z,2) )
local overSpeed = Speed/MaxSpeed
local clampedVector = Vector3.new(PlayerBall.AssemblyLinearVelocity.X/overSpeed, 0, PlayerBall.AssemblyLinearVelocity.Z/overSpeed)
PlayerBall.AssemblyLinearVelocity += (MovementVector*150 * (dt)) * (1 - clampedVector:Dot(MovementVector) / MaxSpeed)
end)