Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Placing system is offset by a few studs?

Asked by 5 years ago
Edited 5 years ago

Hello! I have been trying to replicate the placing system from the game Raft and it works, but the object is offset by a few studs

My Placing: https://i.imgur.com/tCenwu9.png

Raft's Placing: https://i.imgur.com/aQQeHOe.png

I'm ONLY asking about the placing, not anything else

My Client Sided Code:

wait()
print("RUNNING")
local m = game.Players.LocalPlayer:GetMouse()
local rotateAmount = 1.5707963267949 -- 90 degree rotation
--local looseRotationAmount = 0.00017453292519943 -- 0.01 (very small rotation) (For Misc Item Placement)
local turnDegress = rotateAmount
local cframe

m.KeyDown:Connect(function(k)
    print(k)
    if k == "r" then
        if turnDegress > 6.2 then
            turnDegress = 0
        end
        turnDegress = turnDegress + rotateAmount
    end
end)

function roundBy7x7Grid(cf)
    local x,y,z = cf.X,cf.Y,cf.Z
    return (CFrame.new(x-(x%7),y-(y%7),z-(z%7)))
end

--[[

    Okay, so, for now, I'm just using the "Foundation" blueprint
    I will use a different blueprint but this one is just for testing purposes

--]]

local bPrintValue = script.Parent.Blueprint
bPrintValue.Value = game.ReplicatedStorage.RaftParts.Foundation.Object.Model
local blueprint = bPrintValue.Value:Clone()
blueprint.Parent = workspace.CurrentCamera
m.TargetFilter = blueprint

--local animTrack = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Swing)
local playingAnim = false

--animTrack.KeyframeReached:Connect(function(kf)
--  if kf == "Stop" then
--      playingAnim = false
--  end
--end)

script.Parent.Blueprint:GetPropertyChangedSignal("Value"):Connect(function()
    print("ERROR?")
    if bPrintValue.Value then
        blueprint:Destroy()
        blueprint = bPrintValue.Value:Clone()
        blueprint.Parent = workspace.CurrentCamera
        m.TargetFilter = blueprint
    else
        game.Players.LocalPlayer:Kick("Blueprint Error. Please Rejoin\n\nData did save")
    end
end)

game.Players.LocalPlayer.Character.Humanoid.Died:Connect(function()
    blueprint:Destroy()
--  while wait(1e7) do end
end)

function check(cf)
    for i,v in pairs(game.ReplicatedStorage._POSITIONS:GetChildren()) do
        if v.Value == cf then
            return false
        end
    end
    return true
end

spawn(function()
    while wait() do
        while script.Parent.Enabled do
            print("YES")
            if check() then
                print("YESYES")
                if game.Players.LocalPlayer:DistanceFromCharacter(m.Hit.p) < 12 then
                    print("DISTANCE")
                    cframe = roundBy7x7Grid(m.Hit) * CFrame.Angles(0,turnDegress,0)
                    print("CFRAME = "..tostring(cframe))
                    if blueprint.PrimaryPart then
                        print("YES")
                        if cframe.Y < 0 then
                            print("ROUNDING ERROR")
                            cframe = cframe * CFrame.new(0,7,0)
                        end
                        print("PLACING")
                        cframe = cframe * CFrame.new(-7,0,0)
                        blueprint:SetPrimaryPartCFrame(cframe)
                    end
                else
                    if blueprint.PrimaryPart then
                        blueprint:SetPrimaryPartCFrame(CFrame.new(0,-100,0))
                    end
                end
                wait()
            end
        end
    end
end)

local down = false
local db = false

--function Animation()
--  if not playingAnim then
--      playingAnim = true
--      animTrack:Play()
--  end
--end

spawn(function()
    while wait() do
        if down then
            print("BUILDING")
            print(#blueprint.PrimaryPart:GetTouchingParts())
--          if #blueprint.PrimaryPart:GetTouchingParts() == 0 then
--              Animation()
                script.Parent.RaftEvent:FireServer(game.ReplicatedStorage.RaftParts.Foundation.Object.Model,cframe)
--          end
        end
    end
end)


script.Parent.Activated:Connect(function()
--  animTrack:Play()
    down = true
end)
script.Parent.Deactivated:Connect(function()
    down = false
end)

If you need the server code, ask me and I'll update the message

0
ooo i love raft. best of luck on your project. royaltoe 5144 — 5y
0
thanks :3 the8bitdude11 358 — 5y

Answer this question