Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

CFrame vs BodyPosition for going through objects?

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

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.

2 comments

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

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.