There is a bug where in my friends game any object that is picked up will be rapidly spinning. This began around when we tried to make a object maintain its orientation (such as in SCP-3008) However, this causes it to spin. All objects are welded beforehand.
Are there any solutions to fix this? Is there a way in order to perhaps optimize the code?
game:GetService("RunService").RenderStepped:Connect(function()
if HoldingItem then
local root = player.Character.HumanoidRootPart
CurrentHolding.MoveRoot.CFrame = mouse.Origin * CFrame.new(0,0,-AwayDistance)
CurrentHolding.MoveRoot.Orientation = Vector3.new(RotationX, RotationY, RotationZ)
--CurrentHolding.MoveRoot.Orientation.Y = RotationY
end
end)
There sorry it took a while I’m new to Dev Forum.
local placing = false
local AwayDistance = 10 -- Can be changed by scrolling
local RotationX = 0
local RotationY = 0
local RotationZ = 0
game:GetService("RunService").RenderStepped:Connect(function()
if HoldingItem then
CurrentHolding.MoveRoot.CFrame = mouse.Origin * CFrame.new(0,0,-AwayDistance)-- * CFrame.Angles(RotationX, RotationY, RotationZ)
CurrentHolding.MoveRoot.Orientation = Vector3.new(RotationX, RotationY, RotationZ)
end
end)
function Release(CurrentHolding)
pickupEvent:FireServer(CurrentHolding, "Replace")
end
function pickup(PickupPart)
HoldingItem = true
print("picked up")
CurrentHolding = PickupPart.Parent:Clone()
CurrentHolding.Parent = workspace
-- // make something idk
local CurrentHoldingChildren = CurrentHolding:GetChildren()
for i=1, #CurrentHoldingChildren do
if CurrentHoldingChildren[i].ClassName == "Part" or CurrentHoldingChildren[i].ClassName == "MeshPart" then
CurrentHoldingChildren[i].CanCollide = false
CurrentHoldingChildren[i].Transparency = 0.5
end
end
pickupEvent:FireServer(PickupPart, "Destroy")
end
input.InputBegan:Connect(function(key)
if key.UserInputType == Enum.UserInputType.Keyboard then
if key.KeyCode == Enum.KeyCode.Q then
if HoldingItem then
HoldingItem = false
Release(CurrentHolding)
end
end
end
end)
mouse.WheelForward:Connect(function()
if AwayDistance < 20 then
AwayDistance = AwayDistance + 1
end
end)
mouse.WheelBackward:Connect(function()
if AwayDistance > 10 then
AwayDistance = AwayDistance - 1
end
end)
game:GetService('RunService').RenderStepped:Connect(function()
if HoldingItem then
CurrentHolding.MoveRoot.CFrame = CFrame.new(player.Character.Head.Position + (((mouse.Hit.Position) - player.Character.Head.Position).Unit * AwayDistance))
end
end)
You had the problem that you were using CFrame of mouse which includes all orientation and positioning of the mouse which rotated the whole part, what I did was created a vector between the head of the player (as you are in first person), this was out start position and our end position was the mouse.Hit which would be shortened down with the AwayDistance number.
From this I drew a basic vector for our direction and added it onto our start position giving us just the position change.
I believe that if you try to rotate it around using orientation or CFrame angles it shall work.
Yes, I suggest out of pure good practice you change object orientation in functions/code that are not linked to a loop to save on execution time that can lower your script’s performance.