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

How Do I Use CFrame In Local Space?

Ok I am making a shoulder cam exactly like shift lock, but for some reason there is no force shift lock I know of. I was having tons of trouble trying to make a camera look like that until I learned I could just set the camera subject to a brick just a little right of the player. I tried to do so like this:

camPart.CFrame = head.CFrame + Vector3.new(-2,0,0)

Everything is in place except for the fact when I rotate the player, the brick stays in its position relative to the Global Space.. e.g. when the player spawns in and is looking along the y axis the part is on the x axis left of the player, when the player looks along the x axis the part is now in front of the player. I believe this problem is caused because I am using Vector 3 on a Global Space Value instead of a Local Space Value. Would anyone please tell me how I could make it so the cube will always stay on the right side of the player at all times/stay within local space of the player?

--By the way I am using the CFrame Value in a function to be ran on BindToRenderStep

1 answer

✓ Accepted answer
camPart.CFrame = head.CFrame + CFrame.new(-2,0,0)

why are you adding CFrame's and Vector3's?

3 comments

0

I tried doing that but it gave me an error saying it wanted a Vector 3, not a CFrame. RunService:fireRenderStepEarlyFunctions unexpected error while invoking callback: Workspace.TheFierceWaffle.CAMERASCRIPT:20: bad argument #2 to '?' (Vector3 expected, got CFrame)

0

I actually just found a solution to the problem.. it wants a Vector 3 value but it needs a CFrame Value to do what I want... If you use a CFrame value inside a Vector 3 it will work.. do like so camPart.CFrame = head.CFrame + Vector3.new(CFrame.new(-2,0,0)).. Thanks GingeyLol, you did not solve the problem but you greatly helped me find a solution.

0

Lol I found an even better way! Do camPart.CFrame = head.CFrame * CFrame.new(5,0,0) works perfectly

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