Connect part to other in pivot point position

I try connect tool to part in raycast position by this script:

Tool.Parent = model
Tool.Handle.CFrame = CFrame.lookAt(ConnectPosition, ToolCurrentPosition) 
Tool.Handle.CFrame = Tool.Handle.CFrame * CFrame.Angles(math.rad(120), math.rad(-90), 0) 

Point to connect:
PartHitPoint

And get this situation:
PartHitTool

Tool connect on center of tool.

How connect tool to part in tool pivot point, as shown on image?

Essentially you just want to offset the axe by the vector from the origin to the tip.

  1. Get the vector from the center to the tip.

    We want to move blue into red. We can do that by subtracting their positions
    local bluevector = workspace.red.Position-workspace.blue.Position
    Taking blue’s position and adding bluevector to it should move blue into red.

    Yup.
  2. So we now have the offset that we need for the axe. Now all you need to do is move the model. You can do that with primary part, pivot, plenty of ways. You just need to offset the position by bluevector (so add them together, newPos = axePos + bluevector

With code

local bluevector =  ConnectPosition - ToolCurrentPosition 
Tool.Handle.CFrame = CFrame.lookAt(ToolCurrentPosition + bluevector, ToolCurrentPosition ) 
Tool.Handle.CFrame = Tool.Handle.CFrame * CFrame.Angles(math.rad(120), math.rad(-90), 0) 

I get same result
Снимок

Tool is connected to the part in the middle,
without taking into account the offset of the pivot point.

Red box it’s connection point

I find solution, for connect by pivot point I use this code:

Tool.Parent = model
Tool.Handle:PivotTo(CFrame.lookAt(ConnectPosition, ToolCurrentPosition))
Tool.Handle:PivotTo(Tool.Handle:GetPivot() * CFrame.Angles(math.rad(math.random(20, 90)), 0, 0) )	

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