#Need help with C0 rotation

1 messages · Page 1 of 1 (latest)

stark pier
#

This is my first time touching roblox scripting and ive been trying to make the Neck's C0's orientation follow the player camera's orientation but I just cant seem to make it follow the orientation without the neck moving... I hope someone can help me.

local Workspace = game:GetService("Workspace")
local RunService = game:GetService("RunService")

local player = game.Players.LocalPlayer
local character = player.Character

local neck = character:WaitForChild("Head"):WaitForChild("Neck")
local camera = Workspace.CurrentCamera

local function updateNeckC0()
local cameraCFrame = camera.CFrame
local rotation = cameraCFrame
neck.C0 = rotation
end

RunService:BindToRenderStep("UpdateNeckC0", Enum.RenderPriority.Camera.Value + 1, updateNeckC0)

gleaming cobalt
#

Nice formatting

eager ginkgo
#

the camera cframe has a translation in it

#

and your never removing it

#

also there is a workspace constant, no need to :GetService() it 😭

#

You should game:GetService("Players") though

eager ginkgo
stark pier
eager ginkgo
stark pier
# eager ginkgo correct

it's working but now the neck is inside the body, is it because the body is the center? do I need to offset it?

eager ginkgo
#

or just offset

stark pier
blissful mulch
#

The Neck had translation that was overwritten

eager ginkgo
#

In studio check what the C0 property is set to

#

for a character

#

by default

#

Whatever's there is the offset/rotation you'll have to add in

stark pier
#

umm wait a sec

solar belfryBOT
#

studio** You are now Level 1! **studio

stark pier
eager ginkgo
stark pier
#

whats the diff between C0 and C1?

blissful mulch
#

Basically flipping it around

stark pier
eager ginkgo
blissful mulch
stark pier
stark pier
blissful mulch
stark pier
#

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local player = game.Players.LocalPlayer
local character = player.Character

local neck = character:WaitForChild("Head"):WaitForChild("Neck")
local camera = workspace.CurrentCamera

local function updateNeckC0()
local cameraCFrame = camera.CFrame
local rotation = cameraCFrame.Rotation * CFrame.Angles(0, math.rad(180), 0)
local offset = Vector3.new(0, 0.75, 0)
neck.C0 = rotation
neck.C1 = offset
end

RunService:BindToRenderStep("UpdateNeckC0", Enum.RenderPriority.Camera.Value + 1, updateNeckC0)

blissful mulch
#

Can you format that like this in your Discord message:

stark pier
#
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local player = game.Players.LocalPlayer
local character = player.Character

local neck = character:WaitForChild("Head"):WaitForChild("Neck")
local camera = workspace.CurrentCamera

local function updateNeckC0()
    local cameraCFrame = camera.CFrame
    local rotation = cameraCFrame.Rotation * CFrame.Angles(0, math.rad(180), 0)
    local offset = Vector3.new(0, 0.75, 0)
    neck.C0 = rotation
    neck.C1 = offset
end

RunService:BindToRenderStep("UpdateNeckC0", Enum.RenderPriority.Camera.Value + 1, updateNeckC0)
stark pier
blissful mulch
stark pier
#
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local player = game.Players.LocalPlayer
local character = player.Character

local neck = character:WaitForChild("Head"):WaitForChild("Neck")
local camera = workspace.CurrentCamera

local function updateNeckC0()
    local cameraCFrame = camera.CFrame
    local rotation = cameraCFrame.Rotation
    local offset = CFrame.new(Vector3.new(0, -1.25, 0))
    neck.C0 = rotation
    neck.C1 = offset
end

RunService:BindToRenderStep("UpdateNeckC0", Enum.RenderPriority.Camera.Value + 1, updateNeckC0)
stark pier
solar belfryBOT
#

studio** You are now Level 2! **studio

stark pier
#

oh but if I add the offset into C0 thats not a problem anymore

#

so now its back to the weird rotate part

#

the neck orientation is fine if i dont move but if my character spins or starts moving, the neck orintation starts getting weird

blissful mulch
stark pier
#

my brain not braining

#

wait a sec

#

I dont understand... isnt there a way to make it so that the neck does not rotate even when the character spins or moves? the only changes to its orientetion can happen only whith the camera

blissful mulch
stark pier
#

local NeckOriginalC0 = neck.C0

#

and then?

blissful mulch
#

No, the position of the C0. We want a new CFrame that only has the position

stark pier
#

how do I take only the position

#

.Position?

blissful mulch
stark pier
#

this?

local NeckOriginalC0 = CFrame.new(neck.C0.Position)

blissful mulch
stark pier
#
local function updateNeckC0()
    local cameraCFrame = camera.CFrame
    local rotation = cameraCFrame.Rotation
    --local offset = Vector3.new(0, 0.75, 0)
    --neck.C0 = rotation + offset
    local NeckOriginalC0 = CFrame.new(neck.C0.Position)
    local NewRotation = NeckOriginalC0 * rotation
    neck.C0 = NewRotation * CFrame.Angles(0, math.rad(180), 0)
end
#

you there? 😭

blissful mulch
stark pier
#

nope

blissful mulch
stark pier
#

the same as before

solar belfryBOT
#

studio** You are now Level 3! **studio

blissful mulch
stark pier
#

wait

blissful mulch
stark pier
#

still has the same problem

#

I appreciate your help bro but I think Imma sleep now... it is 4 in the morning here. I hope we can continue later

blissful mulch
stark pier
#

okay 😊

stark pier
#

ill look into it first

stark pier
#

hmm

#

how do I make it so that lua local NeckOriginalC0 = neck.C0.Position only save the position of the neck on startup and does not reupdate the variable to the latest position, just the intial position

#

im not getting anywhere

#

ill do something else first

#

I guess ill need to wait for you @blissful mulch

stark pier
#
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local player = game.Players.LocalPlayer
local character = player.Character

local neck = character:WaitForChild("Head"):WaitForChild("Neck")
local camera = workspace.CurrentCamera

local function updateNeckC0()
    local NeckOriginalC0 = neck.C0.Position
    local targetPosition = camera.CFrame.Position
    neck.C0 = CFrame.new(NeckOriginalC0, targetPosition) * CFrame.Angles(0, math.rad(180), 0)
    
    --local NeckOriginalC0 = CFrame.new(neck.C0.Position)
    --local cameraCFrame = camera.CFrame
    --local rotation = cameraCFrame.Rotation
    --local NewRotation = NeckOriginalC0 * rotation
    --neck.C0 = NewRotation
end

RunService:BindToRenderStep("UpdateNeckC0", Enum.RenderPriority.Camera.Value + 1, updateNeckC0)

This is my latest test, doesnt work so I think imma do smin else first and come back when I know more abt roblox scripting

stark pier
blissful mulch
# stark pier I guess ill need to wait for you <@268887523822927874>

Different timezones, I was asleep

So for .lookAt, I was imagining using it to look at where the camera is looking at.

Now the issue is that this may make the head point in unnatural angles.

Maybe start here instead:
https://youtu.be/mdXRnNb0S6o

Join my Discord Server and talk to me! https://discord.gg/5kTK7Du

TIMESTAMPS:
0:00 - Intro
1:10 - Initializing HeadMovement Script
2:20 - Observing Neck Motor6D Of Character
3:18 - Run Service Function
4:20 - Testing neck.C0.Y Values
5:42 - CFrame.Angles()
7:20 - Getting Camera Direction LookVector
10:00 - Using Trigonmetry to Get Proper Angles...

▶ Play video
stark pier
#

oh, okay

stark pier
# blissful mulch Different timezones, I was asleep So for `.lookAt`, I was imagining using it to...

It's working now

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local player = game.Players.LocalPlayer
local character = player.Character

local root = character:WaitForChild("HumanoidRootPart")
local neck = character:WaitForChild("Head"):WaitForChild("Neck")
local camera = workspace.CurrentCamera

local CFNew, CFAng, asin = CFrame.new, CFrame.Angles, math.asin

local function updateNeckC0()
    local cameraDirection = root.CFrame:toObjectSpace(camera.CFrame).lookVector
    
    if neck then
        neck.C0 = CFNew(neck.C0.p) * CFAng(asin(cameraDirection.y), -asin(cameraDirection.x), 0)
    end
end

RunService:BindToRenderStep("UpdateNeckC0", Enum.RenderPriority.Camera.Value + 1, updateNeckC0)
solar belfryBOT
#

studio** You are now Level 4! **studio