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

Having issues with BodyGyro based on camera's lookVector?

Over the past day or so I've been working on a glider for my game. I want the player's body to both point in the direction of the camera and to move in the direction the camera is pointing. I have managed to get the torso to move in the camera's direction; however, I'm having trouble rotating it with a BodyGyro. I'm trying to base its CFrame off of the camera's lookVector components. Here's my code:

torsogyro.CFrame = CFrame.new(x,y,z); torsogyro.P = 5000

--x, y, and z are the camera's X, Y, and Z lookVector components respectively.

I've very little experience with BodyGyros, so excuse the atrocious P value. If anybody could tell me what I'm doing wrong, I'd really appreciate it. When running this script, the torso does not rotate at all.

1 answer

✓ Accepted answer

I can't get Gyro to work at all with this, but you'll still need it to stop the stuttering. Here was my setup. You should be able to adapt it to yours.

local player = game.Players.LocalPlayer
repeat wait() until player.Character
local character = player.Character
local bg = script:WaitForChild('BodyGyro')
local hum = character:WaitForChild("Humanoid")
local torso = character:WaitForChild("HumanoidRootPart")
local cam = Workspace.CurrentCamera
hum.AutoRotate = false

bg:Clone().Parent = torso

game:GetService('RunService').RenderStepped:connect(function()
	torso.CFrame = CFrame.new(torso.CFrame.p, cam.CFrame.lookVector * 50000)
end)

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