Meshpart is offset by 90deg

I have been trying to make a bow and arrow for some time now, at first I had thought that the arrow I modelled was just made off-axis, today I made an actual modelled arrow to come across the same issue, I’ve tried to use alignorientation, setting it manually and changing the models pivotpoint all to come up short. I’m going mad here

https://gyazo.com/d91a9cf2d039dcf2d16779d9a762037d

I’m unsure where or if the script is to blame, so sorry in advance for the large codeblock.

local plr = game:GetService("Players").LocalPlayer


local aim = plr.Character:WaitForChild("Humanoid"):LoadAnimation(script.Aim)
local hold = plr.Character:WaitForChild("Humanoid"):LoadAnimation(script.Idle)
local draw = plr.Character:WaitForChild("Humanoid"):LoadAnimation(script.Draw)
local fire = plr.Character:WaitForChild("Humanoid"):LoadAnimation(script.Fire)

local uis = game:GetService("UserInputService")
local ts = game:GetService("TweenService")

local aimsignalin 
local aimsignalout

local temp 
local temp2
local move 
local touchevent

local drawin
local release
local lerpevemt

local drawlength = 0
local drawtime = 0.1

local aiming = false
local livearrow = false

local char = plr.Character
local hum = char:WaitForChild("Humanoid")
local root = hum.RootPart 
local arrow
local weld


local ti = TweenInfo.new(draw.Length, Enum.EasingStyle.Sine)












function shiftLock(active)  
	if active == true then
		hum.AutoRotate = false

		hum.CameraOffset = Vector3.new(1.75,0,0)
		game:GetService("RunService"):BindToRenderStep("ShiftLock", Enum.RenderPriority.Character.Value, function()
			game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.LockCenter 
			---------------------------------------------------------
			local _, y = workspace.CurrentCamera.CFrame.Rotation:ToEulerAnglesYXZ()
			root.CFrame = CFrame.new(root.Position) * CFrame.Angles(0,y,0) 
			---------------------------------------------------------
		end) 
	
		elseif active == false then
		game:GetService("RunService"):UnbindFromRenderStep("ShiftLock")
		hum.AutoRotate = false
		game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.Default 
		hum.AutoRotate = true
		hum.CameraOffset = Vector3.new(0,0,0)
	end
end
local function bezier(t, p1, p2, p3)
	return(1 - t)^2 * p1 + 2 * (1 - t) * t * p2 + t^2 * p3
end









script.Parent.Equipped:Connect(function()
	hold:Play()
	arrow = game:GetService("ReplicatedStorage"):WaitForChild("Items").Arrows[script.Parent:GetAttribute("ArrowType")]:Clone()
	arrow.Parent = script.Parent.bow
	script.Parent.bow.TopConst.Attachment1 = arrow:WaitForChild("End")
	script.Parent.bow.BottomConst.Attachment1 = arrow:WaitForChild("End")
	weld = Instance.new("Motor6D")
	weld.Parent = arrow
	weld.Part0 = script.Parent:WaitForChild("BodyAttach")
	weld.Part1 = arrow:WaitForChild("Shaft")
	aimsignalin = uis.InputBegan:Connect(function(inp, gpe)
		if not gpe and  inp.UserInputType == Enum.UserInputType.MouseButton2 then
			aim:Play()
			shiftLock(true)
			aim:GetMarkerReachedSignal("BowAImed"):Connect(function()
				aim:AdjustSpeed(0)
				aiming = true
				
			end)
		end
	end)
	aimsignalout = uis.InputEnded:Connect(function(inp, gpe)
		if not gpe and  inp.UserInputType == Enum.UserInputType.MouseButton2 then
			aim:Stop()
			aiming = false
			shiftLock(false)
				if lerpevemt then
				lerpevemt:Disconnect()
				end
		end
	end)
	
	
	local num = 0
	local prev = 0
	local diff = 0
	local t
	drawin = uis.InputBegan:Connect(function(inp, uis)
		if not uis and inp.UserInputType == Enum.UserInputType.MouseButton1 and aiming then
			prev = tick()
			draw:Play()
			
			
			
			draw:GetMarkerReachedSignal("DrawBack"):Connect(function()
				draw:AdjustSpeed(0)
			end)
			local added = 0
			lerpevemt = game:GetService("RunService").Heartbeat:Connect(function()
				if aiming and diff <= 1 then
					diff = tick() - prev
				end
			end)
			if diff <= 1 then
						
					else
					end
		end
	end)

	release = uis.InputEnded:Connect(function(inp, gpe)
		if not gpe and  inp.UserInputType == Enum.UserInputType.MouseButton1 then
			draw:Stop()
			if aiming then
				print("final lerped number "..diff)
				fire:Play()
				--weld:Destroy()
				local hit = plr:GetMouse()
				hit.TargetFilter = script.Parent 
				if hit.Hit then
				local hittt = hit.Hit
					temp2 = fire:GetMarkerReachedSignal("Fire"):Connect(function()
					livearrow = true
					weld:Destroy()
					if arrow:FindFirstChild("Shaft") then
					arrow.Shaft.Anchored = true
					script.Parent.bow.TopConst.Attachment1 = script.Parent.bow.bottomatt
					script.Parent.bow.BottomConst.Attachment1 = script.Parent.bow.topatt
					local L = plr.Character.HumanoidRootPart.Position:Lerp(hittt.Position, 0.5) * Vector3.new(1,(diff*5),1)
					
					 
						--[[local prt = Instance.new("Part")
						prt.Parent = workspace
						prt.Anchored = true
						prt.Size = Vector3.new(2,2,2)

						prt.Position = L]]
						
						
						for i = 0,1,0.1 do
						--[[]local part = Instance.new("Part")
							part.Anchored = true
							part.Size = Vector3.new(0.5,0.5,0.5)
							part.Parent = workspace
							part.CFrame = curvecf]]
							if arrow:FindFirstChild("Shaft") then
							local curvecf = CFrame.new(bezier(i, plr.Character.HumanoidRootPart.Position,	L, hittt.Position))
							arrow.Shaft.CFrame = curvecf * CFrame.lookAt(arrow.Shaft.Position, hittt.Position).Rotation
							
							task.wait()
							end
							end
						end

						
						
					task.wait(fire.Length)
					temp2:Disconnect()
				end)
				
				if lerpevemt then
					lerpevemt:Disconnect()
					
				end
					local a = OverlapParams.new()
					a.FilterDescendantsInstances = {plr.Character, arrow:GetDescendants()}
					a.FilterType = Enum.RaycastFilterType.Exclude
				touchevent = game:GetService("RunService").Heartbeat:Connect(function(dt)

						if livearrow then
						local partsinpart = workspace:GetPartBoundsInBox(arrow.Hitbox.CFrame, arrow.Hitbox.Size, a)  --bow detection
						local currentarrow = arrow
							if partsinpart then
								for i, instance in partsinpart do
									if instance.Parent:FindFirstChild("Humanoid") then
									print("hit a plr "..instance.Name)
									touchevent:Disconnect()
									coroutine.resume(coroutine.create(function()
										task.wait(5)
										--currentarrow:Destroy()
									end))
									break
								else
									print("hit something else "..instance.Name)
									touchevent:Disconnect()
										coroutine.resume(coroutine.create(function()
											task.wait(5)
											--currentarrow:Destroy()
										end))
									break
							end  
								
								end
								
						end
					
					
						
					
					end
				end)
				
				
				end
				arrow = game:GetService("ReplicatedStorage"):WaitForChild("Items").Arrows[script.Parent:GetAttribute("ArrowType")]:Clone()
				arrow.Parent = script.Parent.bow
				script.Parent.bow.TopConst.Attachment1 = arrow:WaitForChild("End")
				script.Parent.bow.BottomConst.Attachment1 = arrow:WaitForChild("End")
				weld = Instance.new("Motor6D")
				weld.Parent = arrow
				weld.Part0 = script.Parent:WaitForChild("BodyAttach")
				weld.Part1 = arrow:WaitForChild("Shaft")
		end
			
			num = 0
		end
	end)

	
	
	
end)









--Toggle Function




script.Parent.Unequipped:Connect(function()
	hold:Stop()
	aim:Stop()
	aimsignalin:Disconnect()
	aimsignalout:Disconnect()
	drawin:Disconnect()
	release:Disconnect()
	arrow:Destroy()
	if touchevent then
	touchevent:Disconnect()
	end
	shiftLock(false)
	livearrow = false
end)
1 Like

try finding the part where the bow shoots and i actually can help if is NOT that hard

1 Like

?? you’re gonna have to clarify a little, if you’re talking about the hierarchy of the bow and arrow models here ya go
image
image

They’re just wondering about the part where you set the arrow’s CFrame:

To fix this, you just need to set the CFrame to one that’s rotated 90 degrees.

local unrotatedCFrame = curvecf * CFrame.lookAt(arrow.Shaft.Position, hittt.Position).Rotation
arrow.Shaft.CFrame = unrotatedCFrame * CFrame.Anges(0, math.rad(90), 0)

So replace that line I quoted from your code with those two lines above. If it rotates it the wrong way, try either switching to -90 degrees or change the axis that’s being rotated (e.g. CFrame.Anges(math.rad(90), 0, 0) etc).

worked beautifully, thank you I have been going mad over this for weeks now :sob:

1 Like

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