# Tween a part 50 studs away from point a in the direction of point b

What I want to achieve is basically when you click, it tests if the target is too far or not; if it’s close enough (within 50 studs) it’ll grapple onto that object. If it’s further than 50 studs away, I want the part to only tween 50 studs away, so basically how do I get the CFrame for 50 studs away from point a with the direction to point b
I’ve tried using Unit, but I don’t think I’m using it right so I’m asking here

You can try unit by doing

``````(PointB.Position - PointA.Position).Unit * 50
``````
1 Like

I need to tween the CFrame, unit only works on vector3s so how would I do that?
(what I have right now: `local cf = (newHand.main.CFrame - newHand.main.CFrame.Position) + mousePos.Unit * 50`)

Everytime i try this,
`local cf = (newHand.main.CFrame - newHand.main.Position) + (mousePos - newHand.main.Position).Unit * 50` (cf is the point im tweening to after calculating where it is)
It tweens the hand to the middle of the workspace
(newHand.main == point a, mousePos == point b)

Why would you need to keep a CFrame? If you wanna tween off of the CFrame, just add the directional vector to it and the hand will go out 50 studs towards that direction.

``````local cf = newHand.main.CFrame + (mouse.Hit.Position - newHand.main.CFrame.Position).Unit * 50
``````

First you need to find a `CFrame` that is orientated in the right direction.

``````local start = CFrame.new(partA.Position, partB.Position)
``````

Next you need to move that `CFrame` in the look direction by 50 studs.

``````local target = start + start.LookVector * 50
``````

This `target` is your final `CFrame`. However if you do not want the `partA` to rotate in the grapple direction, you can use:

``````local targetCFrame = partA.CFrame - partA.Position + target.Position
``````

I assuming you already know this, but the best way to calculate distance is:

``````local distance = (partA.Position - partB.Position).Magnitude
``````

Im gonna try all this tomorrow, gonna go sleep now. Thank you all for your responses!

Thank you so much for your reply, this worked. I’m sure the answer below would’ve worked too but Longing answered sooner and I can only mark one as the solution, anyways thank you all for your responses again!