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

CFrame vs BodyPosition for going through objects?

Asked by 5 years ago
Edited 5 years ago

I was making something and I want a brick to follow the mouse but on the nearest surface that the mouse is over. I have this:

wait(.25)
mousepointto = mouse.Hit.p
brick.CFrame = CFrame.new(mousepointto)
mouse.Button1Up:Connect(function() ... end)

inside a while true loop. It works fine but snaps to the position of the mouse and is not able to overlap other object other objects. I want to make the movement smoother and have the ability to overlap objects.

Anyone have any ideas on how I can do this? brick.Position = mousepointto has the same effect as CFrame

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

The brick does not go through other bricks because... the mouse is 2 dimensional. The hit property of the mouse is the position to where the mouse is pointing, but we only have two dimensions, we don't know if the mouse is 'farther back' or 'forward'. I don't really know how else to explain this, so hopefully, you understand what I am getting at.

I don't really know of a way to do what you are trying to achieve, however, I can suggest one thing: maybe add something to let the players move the item forward/back? Or, just have a 2d placement system where you can only move the item on the X and Y axis.

0
Srry I have no idea what you mean. I agree that the mouse in general is 2-dimensional but Hit is the Position is 3D space since if you snap a brick it will show up where the mouse is pointing to. I really want it to let the player use mouse movement to place the object fa_QURobloxXD 29 — 5y
0
Yes, but since the mouse is 2 dimensional, we have no idea of knowing what the position the mouse is on the Z axis. Because of this, the Z axis is automatically assigned to the position where the mouse 'hits' another object. That is why when you CFrame the part to the mouse's hit property, it still does not go through other parts. Operation_Meme 890 — 5y
Ad

Answer this question