Help with Rocket Building System

(Sorry for bad english! It is not my first language.)

Hi! I’m working on a rocket building system that makes the rocket part face the surface it’s on and it’s not working really well…

Whenever i select a rocket part, The said rocket part only works if its on a certain area relative to the part the rocket part is on.

Here’s a video for context:

The rocket part i selected only faces a certain surface. It doesn’t really work on the wedge cause it only works if your mouse is on the sloped surface.

If the system is utilizing RayCast, make the part have the following CFrame applied:
RocketPart.CFrame = CFrame.new(RayResults.Position, RayResults.Position + RayResults.Normal)
RayResults is value returned from the function :Raycast() of workspace.
It’s best to use Raycasting for such stuff.
If the problem is still there then it’s the MeshPart’s collision itself that’s the problem here.

1 Like

That’s exactly what im doing, Yet it still doesn’t work, Setting the meshpart’s collision to PreciseConvex lags the game since the meshpart will be scaled to create a planet. I can give you the script for context!

local CollectionService = game:GetService("CollectionService")
local UIS = game:GetService("UserInputService")
local Grid = 0.1
local mouseMove
local equipfunc
local isDragging = false

local plr = game.Players.LocalPlayer
plr.CharacterAdded:Wait()
local chr = plr.Character

local mouse = plr:GetMouse()

mouse.Button1Down:Connect(function()
	if chr:FindFirstChild("Hammer") and chr:FindFirstChildWhichIsA("Tool") then
		if isDragging then return end
		if mouse.Target == nil then return end
		if not CollectionService:HasTag(mouse.Target, "Draggable") then return end
		isDragging = true
		if equipfunc ~= nil then
			equipfunc:Disconnect()
		end
		local TargetModel = mouse.Target.Parent
		local hammerTool = chr:FindFirstChild("Hammer")
		
		equipfunc = hammerTool.Unequipped:Connect(function()
			if mouseMove ~= nil then
				mouseMove:Disconnect()
			end
			mouseMove = nil
			isDragging = false
			return
		end)
	
		
		local PosX, PosY, PosZ
		
		local function Snap()
			
			PosX = math.floor(mouse.Hit.X / Grid + 0.5) * Grid -- Snaps
			PosY = 0
			PosZ = math.floor(mouse.Hit.Z / Grid + 0.5) * Grid -- Snaps
		end
		
		local function Move()
			TargetModel.Parent = game.Workspace
			mouse.TargetFilter = TargetModel
			Snap()
			TargetModel:SetPrimaryPartCFrame(CFrame.new(PosX, mouse.Hit.Y, PosZ) * CFrame.new(0,1,0) * CFrame.Angles(math.pi/2,0,0))
			
			local origin = TargetModel.PrimaryPart.Position
			local direction = mouse.Hit.Position
			
			local raycastParams = RaycastParams.new()
			raycastParams.FilterType = Enum.RaycastFilterType.Include
			raycastParams.FilterDescendantsInstances = {mouse.Target}
			
			local raycastResult = workspace:Raycast(origin, direction, raycastParams)
			
			if raycastResult and raycastResult.Instance then
				print("POS: ",raycastResult.Position, "     NORM: ", raycastResult.Normal)
				TargetModel:SetPrimaryPartCFrame(CFrame.lookAt(raycastResult.Position, raycastResult.Position + raycastResult.Normal) * CFrame.new(0,1,0))
				
			end
			-- raycastResult.Position + raycastResult.Normal
			
		end
		
		mouseMove = mouse.Move:Connect(Move)
		
		mouse.Button1Down:Connect(function()
			game.ReplicatedStorage.Remotes.PlaceBuild:FireServer(TargetModel, TargetModel.PrimaryPart.CFrame)
		end)
	end
end)
1 Like

I believe this is just weird behavior caused by whatever CollisionFidelity you are using. Does it still happen when you scale up the part by a lot?

If you are using Default setting, It will not be entirely accurate for precise divots like you have shown. Scaling up the part should help with this. The default setting is like PreciseConvexDecomp but uses voxel-based decomposition. If you have detail more fine than you can make with boxes, it’s gonna look weird

1 Like

does changing the part’s collision fidelity fix the issue?

1 Like

The meshpart will be scaled to a larger size and used in another game for space exploration.

I’m sure not the collisionfidelity’s problem, I tried a wedge but it only works when i point it on the sloped surface.

Here, try this. Because you have your raycastParams set to only include the object you are moving, you won’t ever get the correct value for the normal.

This snaps to objects using the camera as the starting point for raycasting, and has a properly formed filter

local function Snap(pos : Vector3)

	return Vector3.new(
		math.floor(mouse.Hit.X / Grid + 0.5) * Grid, -- Snaps
		pos.Y,
		math.floor(mouse.Hit.Z / Grid + 0.5) * Grid -- Snaps
	)		
end

local function Move()
	TargetModel.Parent = game.Workspace
	mouse.TargetFilter = TargetModel
	
	local origin = cam.CFrame.Position
	local direction = mouse.Hit.Position - origin
	
	local raycastParams = RaycastParams.new()
	raycastParams.FilterType = Enum.RaycastFilterType.Exclude
	raycastParams.FilterDescendantsInstances = { TargetModel, chr }
	
	local raycastResult = workspace:Raycast(origin, direction * 50, raycastParams)
	
	if raycastResult then

		local pos = Snap(raycastResult.Position)

		TargetModel:SetPrimaryPartCFrame(CFrame.new(pos, pos + raycastResult.Normal))				
	end
end

Thank you! Sorry for sounding like i just wanted scripts, I just needed help for the raycasting n stuff.

1 Like

You have nothing to be sorry for :blush: Your question was more well-formed than many others I’ve seen. You have also been polite, a lot of people on this website like to argue for the sake of arguing.

1 Like