hi, so basically im just skipping to the point, i have a custom camera script for a grabbing system, it works fine, however my character doesnt turn with the mouse. i tried using align orientation and body gyro, but those still didnt work.
heres the needed parts for the problem
script
RunService.Stepped:Connect(function()
UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
CameraData.CamPos = CameraData.CamPos + (CameraData.TargetCamPos - CameraData.CamPos) *0.28
CameraData.AngleX = CameraData.AngleX + (CameraData.TargetAngleX - CameraData.AngleX) *MouseData.Smooth
local dist = CameraData.TargetAngleY - CameraData.AngleY
dist = math.abs(dist) > 180 and dist - (dist / math.abs(dist)) * 360 or dist
CameraData.AngleY = (CameraData.AngleY + dist *MouseData.Smooth) %360
camera.CameraType = Enum.CameraType.Scriptable
camera.CameraSubject = Player.Character.HumanoidRootPart
camera.CFrame = CFrame.new()
* CFrame.Angles(0,math.rad(CameraData.AngleY),0)
* CFrame.Angles(math.rad(CameraData.AngleX),0,0)
+ Character.HumanoidRootPart.Position
+ Vector3.new(0,1.5,0)
Step = Step + 1 -- this part is about grabbing system, dont know if its needed or not
if Step % 3 == 0 then
if Grabbing then
local BaseCFrame = camera:GetRenderCFrame()
PosAtt.WorldPosition = BaseCFrame.Position + (BaseCFrame.LookVector.Unit*7)
local RayCast =
Ray.new(Character.HumanoidRootPart.Position,Vector3.new(0,-3,0))
local Hit = workspace:FindPartOnRay(RayCast, Character)
if CameraData.AngleX < -75 or Hit == Part then
if Part and Align then
Align:Destroy()
Grabbing = false
end
end
end
end
end)
before the .stepped, i used this code for it local PosAtt = Instance.new("Attachment",workspace.Terrain) - posatt is needed for grabbing system local BG = Instance.new("BodyGyro")
BG.Parent = Player.Character.HumanoidRootPart
and in the stepped function, i used this. BG.D = 300 BG.P = 300000 BG.MaxTorque = Vector3.new(400000000, 0, 400000000) BG.CFrame = PosAtt.CFrame
none of the parts are anchored, and i get this when using the red circle things, what am i doing wrong here? im new to bodygyros so i dont understand it well
local PosAtt = Instance.new("Attachment",workspace.Terrain)
BG.CFrame = PosAtt.CFrame
instead of that do
local PosAt = Instance.new("Attachment",workspace.Terrain)
BG.CFrame = CFrame.lookAt(HumanoidRootPart.Position,PosAtt.WorldPosition)
Explanation.
The CFrame works by using the lookat instad of making an entirely new one.
There is a better way to put this I think.
Position and CFrame are not the same thing. CFrame has a position and and orientation.
Also do worldPosition instead of Position usually to get it Relative to the world. Ofcourse in your case you don’t have to because you are setting the parent to the Terrain but I think it is better practice to.