How would I make a custom character follow the camera on the X axis?

https://gyazo.com/333ef01c7a852c68f128c0c5d912b19c

I’ve tried using ToWorldSpace but the player floats to the camera.

This is my own character controller

Here’s the code

local offsetCFrame = CFrame.new(game.Workspace.CurrentCamera.CFrame.LookVector)
plra.CFrame = plra.CFrame:ToWorldSpace(offsetCFrame)
1 Like

Do you mean move towards the mouse position?
Or something like a custom shift lock?

No I mean move in the direction the camera is. It’s a custom controller I’m developing not a custom shift lock.

I’ve tried using UpVector RightVector but there’s none for forwards and backwards.

Do you have a video of what you are trying to achieve? I don’t understand the effect.

Are you talking about moving to the mouse? Or going forward to where the camera is facing?

Did you read what I just said?

Again. Can you please look at this?

That’s a video showing your bug, not what you want to make.

Yes, I read it. I just don’t understand what you mean by this? That’s why I am asking…
From what I understand, you want to achieve this:
image
Is that correct?

Yes that is indeed correct.
Just lookvector or any others aren’t working.

I am not completely sure, but I believe you can use BodyGyro (to face towards the Camera LookVector) on the main part of the character.

I’ll test it real quick and get back to you.

The character is anchored and also uses my own gravity system.

1 Like

Here’s the updated code btw. It doesn’t stay on the X axis though.

		local offsetCFrame = CFrame.new(-game.Workspace.CurrentCamera.CFrame.ZVector)
		plra.CFrame = plra.CFrame * offsetCFrame

So you want something like this?

No I mean with a movement system not a look at camera thing.

I was able to achieve this effect by constantly CFraming.
I don’t have your character, but all parts are connected to each other, so you can just use something like this:

local RunService = game:GetService("RunService")
local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait() --Get the character
local cam = workspace.CurrentCamera
local speed = 2 --CFraming speed
RunService.RenderStepped:Connect(function() --Every frame do
	char:SetPrimaryPartCFrame(char:GetPrimaryPartCFrame() + Vector3.new(cam.CFrame.LookVector.X * speed,0,cam.CFrame.LookVector.Z))
	--^Move towards the X and Z of the camera
end)

--This is a local script

I don’t know whether your game is 2D or 3D, so I made mine with both X and Z.
Just replace speed,0,cam.CFrame.LookVector.Z with 0 if you want it only on the X.

Result:

Works like a charm! Thank you very much!

1 Like