Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

This character body gyro script isn't working, and I have no idea how to fix it. Help??

Asked by 6 years ago

I'm trying to make my character body turn left or right (not up and down) based on camera direction using a BodyGyro. I thought I knew how, but apparently, I don't know how because it's not working. No errors, it just doesn't move when I turn the camera (shocker, right?)

Here's what I have that's important. I was hoping I could come here to get some help since the forums shut down. I've tried everything and have no idea how to fix.

bodyGyro.CFrame = CFrame.new (game.Workspace.CurrentCamera.CFrame.lookvector.X, 0, game.Workspace.CurrentCamera.CFrame.lookvector.Z)  

The bodyGyro is in the torso, by the way.

0
Is that in a localscript? Tio_Kills 5 — 6y
0
yes CodeAspects 0 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

The CFrame.new constructor uses two parts: a position and an orientation. In this example, you want the position to be in the camera, and the orientation to be the direction the camera is looking. To make this orientation, you input a point in 3D space. Roblox makes the orientation by finding the orientation of a part at the position looking at the point you input. Conveniently, however, the camera already has a CFrame Property.

bodyGyro.CFrame = game.Workspace.CurrentCamera.CFrame
Ad

Answer this question