Made the character look where the camera looks... but there is a problem

So hi… again… if someone is here :grinning:

So i made a thing, where the character’s UpperTorso looks where the camera looks. Fine and dandy but when it leans foward the torso snaps to a weird orientation.

See, the thing is, i don’t even know where to start with this. What went wrong? But at least i isolated it.

local waist = script.Parent:WaitForChild("UpperTorso"):WaitForChild("Waist")
local ans = script.Parent.CamAns

function answears(plr,look,origin)
	waist.C0 = CFrame.new(waist.C0.p, (Vector3.new((look.X - origin.X) / 10,(look.Y - origin.Y + .75) / 10,(look.Z - origin.Z) / 10)))
end

ans.OnServerEvent:Connect(answears)

The part with the problem.

Vector3.new((look.X - origin.X) / 10,(look.Y - origin.Y + .75) / 10,(look.Z - origin.Z) / 10)

How should i start solving this? If you need the file i can upload it. Just please guys help.

5 Likes

Maybe just set the waist CFrame to the camera CFrame. Not the whole CFrame just the CFrame.LookVector

waist.CFrame.LookVector = camera.CFrame.LookVector
1 Like

Better way of doing this

local remoteEvents = game.ReplicatedStorage:WaitForChild("RemoteEvents");

local neckC0 = CFrame.new(0, 0.8, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1);
local waistC0 = CFrame.new(0, 0.2, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1);

remoteEvents.tiltAt.OnServerEvent:Connect(function(player, theta)
	local neck = player.Character.Head.Neck;
	local waist = player.Character.UpperTorso.Waist;
	
	neck.C0 = neckC0 * CFrame.fromEulerAnglesYXZ(theta*0.5, 0, 0);
	waist.C0 = waistC0 * CFrame.fromEulerAnglesYXZ(theta*0.5, 0, 0);
end)

-- back in the client script
local remoteEvents = game.ReplicatedStorage:WaitForChild("RemoteEvents");

local function onUpdate(dt)
	updateArm("Right");
	updateArm("Left");
	remoteEvents.tiltAt:FireServer(math.asin(camera.CFrame.LookVector.y));
end

FINALLY… PEOPLE
@SnarlyZoo The event requests the camera LookVector already.
@luaVovert I will try that but… don’t quite understand the content of the script.

1 Like

“Better” Dude, this has about 6 missing functions and variables. If you’re going to claim your method is better, don’t give broken code.

1 Like

Just came back from the bath…
Checked the code aaaand, @MrMauio is right.

1 Like

As for the actual problem, maybe try applying a limit to the X rotation, so it doesn’t go too far forward. You may be giving the engine numbers it doesn’t quite understand, and it’s snapping the waist to an unexpected position, for lack of a better way of wording it.

1 Like

Okay but what about when he turns back with his whole body?
His body doesn’t turn all the way down. That is the reason why i thought the calculations the code does with the CFrames is wrong.

I was super slow to reply btw :laughing: sorry

1 Like

Uhhh…I actually don’t know. Could you send the contents of the localscript so I can test this myself?

1 Like

Sure thing.
Baseplate.rbxl (18.8 KB)
Things are in: PlayerScripts and CharacterScripts

1 Like

Uhhh…

I appear to be suffering a problem while looking around. Is this one different than what’s shown in the video?

2 Likes

hmmm…
that… hmm…
that is why this part is here:

1 Like

Okay, I’m probably just stupid, but this is kinda confusing. Gimme a little bit to try to fix this, please. If I can’t, then maybe someone else can.

1 Like

Ight.
So… we run the RequestCam that sends a request to the client to share where the camera is looking (LookVector). Then the LocCam sends it (roblox doesn’t allow this kind of data to be known by the server (or any other player data) by default so we have to get it somehow).

(btw we get where the HumanoidRootPart is facing too because while testing it lagged behind if we were to mesure from the BodyRotate)

BodyRotate is the brain of it.
We take the Motor6D that connects the UpperTorso and LowerTorso.
function answears(plr,look,origin) this is where you got stuck i think.

plr: player… obv
look: camera LookVector
origin: HumanoidRootPart LookVector (so the script knows just from where it should rotate it from)

We set the Waist CFrame by doing this: (look.X - origin.X) / 10 the /10 is to not over rotate.

You are not dumb it’s just a mess. And i thank everyone who helps. :grinning:

1 Like

Okay, so, I rewrote a bunch of it, and I think I got something that works well!

2 Likes

Baseplate (1).rbxl (19.0 KB)
Here’s the new version of it. Feel free to modify it however you’d like. If there’s anything I did wrong, lemme know.

Instead of doing a bunch of complicated Vector3 stuff, I opted to just look ahead of where the camera was, and it seems to work good!

2 Likes

Finnaly. Someone who helped.The past 2 months have been worth it.

Looks like it works perfectly. Do you need credit? What was wrong?

1 Like

I forgot to attach it lol, also wanted to see if I could do something before posting it

1 Like

Wait…
I mean thx… but it overrotates when turning the whole body.
How do i fix that?

btw uploading on forums is broken

1 Like

o h hold on, I didn’t actually try moving, lemme see if I can fix that. Sorry!

2 Likes