Moving upwards in local space, but code is at fault

Hello, this is my first topic on the devforum. Rn i’m having an issue.

I’m trying to make a character move 5 studs upward in local space. The issue is that my code is giving incorrect results.

Code:
workspace.Noob:SetPrimaryPartCFrame(workspace.Noob:GetPrimaryPartCFrame()+workspace.Noob:GetPrimaryPartCFrame():vectorToObjectSpace(Vector3.new(0, 5, 0)))

Before:

Before picture

After:

After picture

Any help will be greatly appreciated

I’m assuming by local space you mean the noob’s local space. In this case you can easily do:

local origin = workspace.Noob:GetPrimaryPartCFrame()
workspace.Noob:SetPrimaryPartCFrame(origin * CFrame.new(0,5,0))

Basically multiplying CFrame matrices is like “applying a local offset to another local offset”, so in this case we’re applying 5 stud offset on the y in the origin’s local space.

I also want to mention that SetPrimaryPartCFrame starts shifting its children around when called multiple times, so I would advise against using this function in a loop or something.

4 Likes

Ah, ty

1 Like