Issues with creating a PC/Mobile friendly building system

Hello friends.

I have created a very simple snap-to-part building system that allows players to move models and baseparts into place by positioning the model or basepart at the position of a raycast result using this following code:

local RayDirection = (Mouse.Hit.Position - Character.Head.Position).Unit * 30;
	local RaycastResult = workspace:Raycast(Character.Head.Position, RayDirection, RayParams)

This actually works great on both PC and mobile devices (almost). The system is very simple, and to place the object, you simply click or touch.

Here’s where the issue is:

When using UserInputType.Touch to place the object, the system becomes very difficult to navigate using mobile devices, because anytime you attempt to swipe the screen to adjust your camera angle, the touch event is registered and the part is placed in an undesired location.

I attempted to work-around this by adding a “Place” button that you could simply tap on mobile devices, but of course when tapping the button the “mouse” location is still moved to the 3d space behind the button. So this quick work-around did not work as the object would basically be placed wherever I clicked the button.

Is there any way I can make the button to where tapping on it does not reposition the mouse in 3d space?

if not, I would like to change the system to position objects using a raycast from the characters head to directly in front of them a certain distance.

The only issue with that is I don’t know how to cast a ray in the direction that the characters head is facing using the CFrame.LookVector property to where the object is always in front of the player regardless of orientation.

Any ideas?

UserInputService | Roblox Creator Documentation If you look at the different UIS events, you should find a suitable one. Maybe do TouchTapInWorld to position the object and TouchLongPress to place it.

local UIS = game:GetService("UserInputService")
UIS.TouchTapInWorld:Connect(function(pos, ui) 
	local RayDirection = (Mouse.Hit.Position - Character.Head.Position).Unit * 30;
	local RaycastResult = workspace:Raycast(Character.Head.Position, RayDirection, RayParams)
end)

UIS.TouchLongPress:Connect(function(position, state, gpe) 
	if state == Enum.UserInputState.End then
		--Stop the player from updating the position of the part
	end
end)

Something like this

2 Likes

You can mark it as the solution to close the post

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.