#Client Side Placement System Troubles

1 messages · Page 1 of 1 (latest)

past grove
#

How can you perform WorldRoot operations (e.g. GetPartsInBox(), Raycasting, those types of operations) on the client side without being forced to constantly communicate back and forth with the server? (obviously you must communicate with the server when you place a block, talking about when you move your mouse and the ghost block moves it needs to detect other blocks around it to ensure the block which can be rectangular does not phase into others) Thank you in advance.

simple crane
#

Ghost block would be on the client

#

then the client would tell the server to place at this spot

#

then just verify if thats valid

past grove
#

Oh, when I tried workspace:GetPartsInPart() didnt work

past grove
#

I don't know how to perform WorldRoot operations such as GetPartsInPart() on the client side. I always thought that could only be done on the server side

simple crane
#

there are some stuff that are only available through the server

#

isnt much tho

#

like Network ownership

#

only in server

past grove
#

Ohh

#

Perhaps that could be the cause

simple crane
#

and even some stuff thats only on clients

past grove
#

So, you can only detect parts that exist on the server side by settings those parts network ownership? I'm a little confused

#

Nevermind, my problem is accessing the WorldRoot on the client I believe

#

I'm an idiot. Was literally moving stuff on the wrong side...

simple crane
#

when the server makes changes it "replicates" to the client

#

now the client can see them

past grove
#

Ok but what if I create a part on the client, like my ghost part. It wont exist in WorldRoot and the position wont be updated so shouldn't it not work with things like GetPartsInBox?

simple crane
#

the client to server boundry doesnt affect it

#

like why do you need the server to know your doing this x thing like input stuff

past grove
#

Oh that sucks

past grove
simple crane
past grove
#

Do you not understand?

simple crane
past grove
#

Yes, that's literally why I came here. I am asking if you do not understand what im trying to achieve

simple crane
past grove
#

Yes

simple crane
past grove
#

With collisions

simple crane
past grove
#

I don't want the part to be able to intersect other parts

#

Even if the mouse is not over the part that is intersecting

#

I could just use the normal of the part my mouse is over and do that, but what if my mouse is not actually over the intersecting part?

simple crane
past grove
#

I have to use GetPartsInBox() to determine that, which also means accessing WorldRoot which is my problem

simple crane
#

workspace is a global variable

#

or you can use game.Workspace

#

or game:GetService("Workspace")

past grove
#

Those all basically the same though correct?

#

I usually just use workspace

simple crane
past grove
#

Ok so we have that

#

But now, I need to find intersecting parts (parts inside the ghost part)

#

Have you ever played Plane Crazy?

simple crane
past grove
#

So you know how the collision system acts

#

Something like that

simple crane
past grove
simple crane
#

once again you dont need the server side for it to work

past grove
#

I'm puzzled

past grove
simple crane
past grove
#

If that isnt already clear lol

#

@simple crane while wait(0.1) do for _, part in pairs(workspace:GetPartBoundsInBox()) do print(part.Name) end end

#

It's not printing anything whatsoever

#

wait..

#

I'm an actual dumbass LOL

#

Ok fixed it still not printing anything

past grove
#

I know that was what I forgot

simple crane
#

is the code even running?

past grove
past grove
simple crane
#

your using GetPartBoundsInBox not GetPartsInPart

#

you need a cframe and size for GetPartBoundsInBox to work

past grove
#

Oh my bad, ill try the other

#

Oh wait

#

I'll try the box one, should be better on performance

#

Hm, still no print. I'm moving a part inside of it and nothing happens

simple crane
#

is that in a localscript

past grove
#

Yes

simple crane
past grove
#

wait

#

You mean the LocalScript cannot exist within the workspace?

simple crane
past grove
#

And that brings me to my first problem

#

h o w

simple crane
past grove
#

Do I have to do the calculations for intersecting parts myself (I already made it)

past grove
#
    local cframe = part.CFrame
    local halfSize = part.Size / 2

    local corners = {
        cframe:PointToWorldSpace(halfSize),
        cframe:PointToWorldSpace(-halfSize),
        cframe:PointToWorldSpace(Vector3.new(halfSize.X, halfSize.Y, -halfSize.Z)),
        cframe:PointToWorldSpace(Vector3.new(halfSize.X, -halfSize.Y, halfSize.Z)),
        cframe:PointToWorldSpace(Vector3.new(-halfSize.X, halfSize.Y, halfSize.Z)),
        cframe:PointToWorldSpace(Vector3.new(-halfSize.X, -halfSize.Y, -halfSize.Z)),
        cframe:PointToWorldSpace(Vector3.new(halfSize.X, -halfSize.Y, -halfSize.Z)),
        cframe:PointToWorldSpace(Vector3.new(-halfSize.X, halfSize.Y, halfSize.Z))
    }

    local min = Vector3.new(math.huge, math.huge, math.huge)
    local max = Vector3.new(-math.huge, -math.huge, -math.huge)

    for _, corner in pairs(corners) do
        min = Vector3.new(
            math.min(min.X, corner.X),
            math.min(min.Y, corner.Y),
            math.min(min.Z, corner.Z)
        )
        max = Vector3.new(
            math.max(max.X, corner.X),
            math.max(max.Y, corner.Y),
            math.max(max.Z, corner.Z)
        )
    end

    return Region3.new(min, max)
end

local function DoAABBIntersect(part1: Instance, part2: Instance)
    local AABB1, AABB2

    AABB1 = part1.AABB or CalculateAABB(part1)
    AABB2 = part2.AABB or CalculateAABB(part2)

    return not (
        AABB1.Max.X < AABB2.Min.X or AABB1.Min.X > AABB2.Max.X or 
        AABB1.Max.Y < AABB2.Min.Y or AABB1.Min.Y > AABB2.Max.Y or
        AABB1.Max.Z < AABB2.Min.Z or AABB1.Min.Z > AABB2.Max.Z
    )
end```
simple crane
#

workspace:GetPartBoundsInBox gets intesecting parts

past grove
#

Yeah

#

All I need

past grove
simple crane
#

you sure?

past grove
#

My game is going to consist of rectangular objects that can only be rotated in 90 degree increments so yes

#

I only need the AABB bounding box

simple crane
#

alr then it should work

past grove
#

I already thought of this, but imagine having to run it over potentially thousands of blocks

simple crane
#

Region3 is deprecated btw

past grove
simple crane
past grove
simple crane
#

WorldRoot:FindPartsInRegion3() is deprecated

#

which is the "thing" for

past grove
#

Region3 itself does not say deprecated

simple crane
past grove
#

Actually you have a point

#

I'm gonna stop using Region3

#

I have a new idea

simple crane
#

GetPartBoundsInBox works fine for me on the client

past grove
simple crane
#
while task.wait() do
    print(workspace:GetPartBoundsInBox(workspace.Part1.CFrame, workspace.Part1.Size))
end
past grove
#

I see why its working

#

It's because your parts already exist in the workspace

#

I'm trying to summon a new part on the client side only

simple crane
past grove
#

Interesting, still works if you move stuff around?

past grove
#

Huh! So you are moving it on the client or server side while its running?

past grove
# simple crane client ofc

Alright well, thanks for the help. I appreciate it and will try tomorrow. I have to head out soon so bye