Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[Solved] What would be a proper equation to move a part from the head origin to another point?

Alright, so I want to move a part from Point A (Player's Head) to Point B (a new vector 3 val).

I don't know if it's because it's really late, but I can't really get my head around an equation that could achieve this. I know how to find the difference between each value, but that doesn't actually help me (afaik).

startingPosition = dummy.Head.Position --I'm using a dummy rig as a test model

endingPosition = Vector3.new(-8, 7, -55) --My desired position from the head position

distance = endingPosition - startingPosition

--NewPosition = ?

And before you say, "Oh just change the position to the desired end point" , that's not actually what you're doing here, since the heads position changes as the character walks around, you can't just have the same desired position.

One of the cubes on the left can be viewed as the point B (endPosition) and the head can be viewed as point A (startingPosition)

enter image description here

Sorry if the explanation isn't clear, I'm tired af. Thanks in advance.

2 comments

0

What do you mean by "origin"? Do you want to use raycasting?

0

@RobloxWhizYT Nah I just meant "Starting place" as origin. Sorry for the confusion! I think this is really down to just getting a bit better at matrix math equations/cframe math. 

1 answer

For anyone wondering about how to base a part off of another parts origin, its super simple.

Heres one method I learned:

Part.CFrame = CFrame.new(Part.CFrame * Vector3.new(0, 0, 0)

When you do this, you're taking the Parts position vector and adding the product of the vector3 values times the Up, Back, and Right vectors.

It sounds confusing but you can visualize it like this:

RelativePos = 

CFrame.Position 

+

CFrame.RightVector*X

+ 

CFrame.UpVector * Y

+ 

CFrame.BackVector*Z


1 comment

0

Also sorry, I was looking through old posts and noticed that I never wrote my own solution. Maybe if someone sees this one day, it'll help them out as well. Cheers.

This discussion is preserved as it was. New answers, comments, and votes are closed.