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

What is the best method to make an object placing system of a similar quality to ROBLOX's?

Asked by
movsb 242 Moderation Voter
6 years ago

If you have ever dragged a part around to place it in ROBLOX studio (which you probably have) then you should understand fairly well what I am talking about.

I am trying to make a game that requires an extremely advanced object placing system, that of a similar quality to ROBLOX studio's object dragging system.

The method I have used to place objects is simply using the modulus operator to act as a grid placing system like so:

local move_len = 1; --amount of studs to move by

local function place_obj(obj, mse_p)
    obj.Position = Vector3.new(
        mse_p.X - (mse_p.X % move_len),
        mse_p.Y - (mse_p.Y % move_len),
        mse_p.Z - (mse_p.Z % move_len)
    );
end

However this method does not exactly have a similar quality to ROBLOX studio's object placing system due to the fact that many times depending on the camera angle, the object will often be a said number of studs above the baseplate (if it is being placed on top of the baseplate), and occasionally be a said number of studs above a previously placed object that it is being placed on top of; not to mention, sometimes if the camera is at a certain angle, the object being placed will "run" towards the camera, then be placed far away from the camera, only to continuously "run" towards the camera and be placed far away from the camera again, until the camera angle is changed.

I believe that this behavior is either due to an issue with ROBLOX's mouse.Hit property, or my code to place the object is weak.

Either way, is there a better method for an object placing system that is of a similar or the same quality as ROBLOX studio's?

Thanks

0
To an extent, you are doing it wrong. Remember to round up or down. lukeb50 631 — 6y
0
Do you mean I should be using math.floor and math.ceil? movsb 242 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago

Your place_obj code can be simplified (as lukeb50 indicates) with rounding. ex, rounding to the nearest stud with things like math.floor(mse_p.X + 0.5). Also, you probably want to use CFrame, unless you don't want the object to be able to intersect with other objects. (Do note you have to do extra work to preserve rotation if you're using CFrame and have any rotation on the object.)

The problem you describe in your middle/large paragraphs are because you are using mouse.Hit -- when the part is placed right where the mouse cursor is, the mouse cursor starts pointing to the placed object. This updates mouse.Hit.p to a spot closer to the camera, which causes your script to move the part to the closer location, and this repeats for a while.

A solution is to look into raycasting (using Mouse.UnitRay) to determine what the mouse is pointing at. You can tell it to ignore the part you're placing so that the ray can act as if the part isn't even there.

Ad

Answer this question