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?