Move a Part forward based on another Axis

Good evening!

Recently, I’ve stumbled upon a issue that I don’t have a clue on how to resolve it. I have a Part that I want to move forward based on World’s Axis, using CFrames. I’ve found something similar on Roblox Developer’s page, but the issue is that it doesn’t keep track of the direction that the Part should move towards.

To solve this problem I’ve been trying to use CFrame:ToObjectSpace() in order to get the desired position of my Part relative to the HumanoidRootPart at some distance apart, but I don’t know how to translate this position back to World Space.

local HCF = Character.HumanoidRootPart.CFrame
local TargetPosRelative = Clone.CFrame:ToObjectSpace(HCF).Position + Vector3.new(10, 0, 0)

What must I do in order to achieve something like this, without using Forces or anything else? By getting my target position relative to World Space I want to use TweenService to set this it.

CFrame allows you to go to and from WorldSpace:

CFrame:ToObjectSpace()
CFrame:ToWorldSpace()

To get it back to world space, just do what you did with the ToObjectSpace() thing - with the whole CFrame this time - and it should work

1 Like

Something like this?

			local HCF = Character.HumanoidRootPart.CFrame
			local RelativeCF = Clone.CFrame:ToObjectSpace(HCF)
			local TargetPos = RelativeCF+ Vector3.new(10, 0, 0)
			Clone.Position = TargetPos:ToWorldSpace().Position

For some reason it’s not relative and it keeps spawning in kind of same places?

I do not think this is it. What is the offset you want? Lets say its 10 studs forward.

local destiny = HRP.CFrame + 10*HRP.CFrame.LookVector

destiny is the variable with the final CFrame. Does that work?

1 Like

Yep, it seems to work as I wanted to. Thank you :+1: