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

Having issues with BodyGyro based on camera's lookVector?

Asked by
Vexture 179
7 years ago

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

Log in to vote
1
Answered by
Azarth 3141 Moderation Voter Community Moderator
7 years ago
Edited 7 years ago

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)
Ad

Answer this question