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

Modifying Neck(Motor6D) C0's Rotation CFrame to the Camera's lookVector not working?

Asked by
Jo_Bot 67
6 years ago

I wrote this script:

local player = game.Players.LocalPlayer
local character = player.character
local head = character.Head
local uppertorso = character.UpperTorso
local lowertorso = character.LowerTorso
local camera = game.Workspace.CurrentCamera
local uis = game:GetService("UserInputService")
local rs = game:GetService("RunService")

function headMove()
    local camangle = camera.CFrame.lookVector
    character.UpperTorso.Neck.C0 = CFrame.new(Vector3.new(0,1,0), Vector3.new(camangle.x,camangle.y,camangle.z))
end

rs.Stepped:Connect(headMove)

and it won't Translate correctly, like the head is on a weird rotation and everything, all of the movements of the camera translate to the right type of rotation to the Neck, but the position is off... Any help will be greatly appreciated.

                     _____ 
                   ,-'     `._ 
                 ,'           `.        ,-. 
               ,'               \       ),.\ 
     ,.       /                  \     /(  \; 
    /'\\     ,o.        ,ooooo.   \  ,'  `-') 
    )) )`. d8P"Y8.    ,8P"""""Y8.  `'  .--"' 
   (`-'   `Y'  `Y8    dP       `'     / 
    `----.(   __ `    ,' ,---.       ( 
           ),--.`.   (  ;,---.        ) 
          / \O_,' )   \  \O_,'        | 
         ;  `-- ,'       `---'        | 
         |    -'         `.           | 
        _;    ,            )          : 
     _.'|     `.:._   ,.::" `..       | 
  --'   |   .'     """         `      |`. 
        |  :;      :   :     _.       |`.`.-'--. 
        |  ' .     :   :__.,'|/       |  \ 
        `     \--.__.-'|_|_|-/        /   ) 
         \     \_   `--^"__,'        ,    | 
          ;  `    `--^---'          ,'     | 
          \  `                    /      / 
           \   `    _ _          / 
            \           `       / 
             \           '    ,' 
              `.       ,   _,' 
                `-.___.---' 

0
Shrekk neds hiz hed 2 fawlo de camra! Dunt lett shrekk doun m8ees! Jo_Bot 67 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Hi Jo_Bat, What you're trying to accomplish is quite simple. You're just making it too complicated. You don't need to go and get each axis and set that as the look at, you can just set the Vector3 of the angle itself. Also, the position is messed up because you changed the position to be Vector3.new(0, 1, 0). You want to keep this position the same, so this is how you would do this whole thing.

local players = game:GetService("Players");

players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
        local head = char:WaitForChild("Head");
        local neck = head:WaitForChild("Neck");
        local mouse = plr:GetMouse();
        local camera = workspace:WaitForChild("Camera");

        while wait() do
            local look_at = camera.CFrame.lookVector;

            neck.C0 = CFrame.new(neck.C0.p, look_at); -- Makes the Position the Neck's current position and makes the look at the position the camera is pointing to.
        end
    end)
end)   

Well, I hope I helped and have a wonderful day/night.

Thanks,

Best regards,

~~ KingLoneCat

0
Most is working, but the head rotation for the up/down is not accurate, how could I fix this? I tried adding 90 degrees of rotation to one axis, and that didn't work, any suggestions? Jo_Bot 67 — 6y
0
What do you mean the head rotation for up/down isn't accurate? Lemme see a screenshot if what you mean. KingLoneCat 2642 — 6y
0
Here, These are custom characters, I included 2 just in case... https://ibb.co/drUnGJ (Male) https://ibb.co/mELcGJ (Female) Jo_Bot 67 — 6y
0
Hope these help... Jo_Bot 67 — 6y
View all comments (3 more)
0
lil help plz... Shrek needs his head to follow the character... :P Jo_Bot 67 — 6y
0
Dont let shrek down! Jo_Bot 67 — 6y
0
Sorry, you're using custom characters. My script works as intended on a normal roblox character unless you go in first person mode, which can be fixed. But, it might be the custom character's design. KingLoneCat 2642 — 6y
Ad

Answer this question