I’m not good at explaining things Hopefully you understand.
In my game’s current state, you click a button with the tower icon of the tower you want to place. Then, you tap the spot where you want the tower to be. The tower should move its CFrame relative to the user’s CFrame, but for some reason after the tower moves with the player character for like 1 - 0.5 seconds, my movement is forced to stop and I have to release my hand and place it down on the joystick to move it again. I have no trouble placing down the tower.
Everything works fine on laptop/PC, it’s the mobile support that’s been bugging me. (I’m so sorry, I’m so terrible)
Code that I think is related to this:
local function casttap(touchpos, togetdesc)
local castpar = RaycastParams.new()
castpar.FilterType = Enum.RaycastFilterType.Blacklist
castpar.FilterDescendantsInstances = togetdesc:GetDescendants()
local raytap = camera:ViewportPointToRay(touchpos.X, touchpos.Y)
local result = game.Workspace:Raycast(raytap.Origin, raytap.Direction * 1000)
return result
end
uis.TouchTapInWorld:Connect(function(tappedplace)
if place ~= nil then
lastplacetapped = tappedplace
print(tappedplace)
print(place)
getcast = casttap(tappedplace, place)
local x = getcast.Position.X
local y = getcast.Position.Y +(place.PrimaryPart.Size.Y) / 2 + place["Left Leg"].Size.Y
local z = getcast.Position.Z
local placecframe = CFrame.new(x, y, z)
local primpart = place.PrimaryPart
local orientationX, orientationY, orientationZ = primpart.CFrame.Rotation:ToOrientation()
place:SetPrimaryPartCFrame(placecframe * CFrame.fromOrientation(orientationX, orientationY, orientationZ))
else
lastplacetapped = tappedplace
end
end)
local function initplacetower()
local tower = towersfold:FindFirstChild(foundName)
if tower then
place = tower:Clone()
place.Parent = worktowerfold
placedesc = place:GetDescendants()
for i, v in pairs(placedesc) do
if v:IsA("MeshPart") then
table.insert(accessorynames, v.Name)
table.insert(accessories, v.TextureId)
elseif v:FindFirstChild("Mesh") then
table.insert(accessorynames, v.Name)
table.insert(accessories, v.Mesh.TextureId)
end
end
skincolor = (place:WaitForChild("Head")).Color
local placedesc = place:GetDescendants()
collisionsmod.SetPartToGroup(placedesc, "Towers & Monsters")
end
end
button.MouseButton1Click:Connect(function()
if clickedonce == false then
initplacetower()
clickedonce = true
end
end)
runservice.RenderStepped:Connect(function()
if place ~= nil then
local castpar = RaycastParams.new()
castpar.FilterType = Enum.RaycastFilterType.Blacklist
castpar.FilterDescendantsInstances = place:GetDescendants()
if uis.KeyboardEnabled == true and uis.MouseEnabled == true then --Mouse
getcast = castmouse()
elseif uis.KeyboardEnabled == true and uis.TouchEnabled == true and uis.MouseEnabled == false then --Touch
getcast = casttap(lastplacetapped, place)
elseif uis.TouchEnabled == true and uis.MouseEnabled == true then --Touch/Mouse
getcast = castmouse()
end
if getcast and getcast.Instance then
if getcast.Instance.Name ~= "CanPlaceOn" then
canPlace = false
else
canPlace = true
end
local x = getcast.Position.X
local y = getcast.Position.Y +(place.PrimaryPart.Size.Y) / 2 + place["Left Leg"].Size.Y
local z = getcast.Position.Z
local placecframe = CFrame.new(x, y, z)
local primpart = place.PrimaryPart
local orientationX, orientationY, orientationZ = primpart.CFrame.Rotation:ToOrientation()
place:SetPrimaryPartCFrame(placecframe * CFrame.fromOrientation(orientationX, orientationY, orientationZ))
end
end
end)
So what’s causing the character movement stopping? Sorry if you didn’t get my explanation. I can’t record right now but I’ll try to get it on video