How would I make a dragging system like in Roblox Studio?

Alright so I’m working on a building game and it needs a placement system almost identical to studio’s.
However I’m running into a few problems that are making it very difficult to get it working:

The first issue is pushing the part that is being placed out of other parts (if I just set the part being placed to the mouse hit position it will sink in). I really have no clue how to do that.

The second issue is the grid system (these parts will be placed on a grid). However the grid needs to be offset by some amount based on their building area (some vector that offsets the grid) (also just adding the offset to the position AFTER it has been adjusted to the grid is not what I want).

Sorry if this question is a bit vague.

Hello!

If you’d like to draw the grid, you can use texture objects. Then take an image with only borders and set the size to 1,1. Poof, 1 grid studs. :slight_smile:

You’re searching in the right direction for the mouse position. You can use the mouse target filter, so it will not “see” the object you’re placing.
https://developer.roblox.com/api-reference/property/Mouse/TargetFilter

When talking about the grid offset, I believe you mean the grid size. There is a very cool and easy calculation for that.

Imagine your mouse is at 5,37 and you have a grid of 4 studs. Now you need to know which one is closer, 4 or 8?

If you divide 5,37 by 4( grid size) , you get 1,3425.
If you round that number, you get 1. Now do 1 times 4 (grid size). Bam, the right result. :wink:

Kind regards,
Jonas

1 Like

Alright so I should have explained slightly more.
What I meant by sink in was this https://gyazo.com/c44e77931d8612cc2c268a4fa2923b8e (this is if I just set my part position to my mouse hit position).
What I meant by push out was to push the part that’s sinking in to the slightly transparent part.

What I meant by grid offset was to offset the grid by some vector. In this case it needs to be -1, 0, 0. What should happen is that the part is offsetted by the yellow part to line up with the edge.
https://gyazo.com/baa496985ceade7d9ae50ae85fcec0b1

Not sure what you mean by offset the grid as the grid would cover infinity given you know the grid step size and origin (or any other single point). If you want the part to be “pushed out” then perhaps you could explain or define when and how it should happen.

If you are trying to offset it, couldnt you just add forumulaForMouseInputToGrid * CFrame.new(-1,0,0) ?

If it varys by part size, just do the quick math for it. Assuming that block is a 4x4x4 and you need to offset it by -1, that means that to find the offset for each part, divide its X size by 4 and put that in place of the -1 in the CFrame above.

There is a great guide about how to make a placement system on the dev forum: Creating A Furniture Placement System

Even if you want to make a custom system this should be very helpful in clarifying some issues you are having.

I would follow that tutorial if it didn’t just cover placement on one surface (my game needs it to be on all surfaces). :sad:

Also for grid offset what I mean is this:
What I thought would work but actually doesn’t is this:
Let’s say I have a function that can put any number x onto any number on some grid.
The grid is 4 with no offset.
So if I put in 5 it will give me 4.
However say I want 5 to go to 6 and 1 to go to 2 instead of 5 going to 4 and 1 going to 0.
The offset to get 5 to go to 6 is 2.

tldr; grid(x, grid, offset)
grid(5, 4, 2) = 6
grid(5, 4, 0) = 4

By pushing out I mean move the part out of all intersecting parts.

If you can get the y size of the object, add half of that to the object’s y position, and it won’t be in the ground.

1 Like

Nevermind someone else helped me fix it. But thanks anyway :slight_smile:

Helped you fix it how? What was the resolution proposed to the problem?

2 Likes