Custom Camera/Movement doesn't work together

So I need some help here.
I have a custom camera script, that has a little delay on it to make everything smooth. But with the delay the camera tilts a bit. And because of that little orientation, the player doesn’t walk in a direct straight line.
As shown here.
https://gyazo.com/7dfbd710022d932cd0f3d4e2cd7d9ecb

The only way I found is to fix the delay, but that makes everything look so static.
As shown here.
https://gyazo.com/2c1c8e4f785a208a2ce65860a3807b18

I want to have the smooth camera like the first video, but I want the player to be able to walk in direct lines.

1 thing how I tried fixing this was: when the player hits W the player only moves north, no matter the camera angle. But I couldn’t figure out how to do that.

My question:
Is there a way to fix this?
If my attempt at fixing this was correct (W = north, D = east etc…) How do I execute something like that?

Thank you in advance.

If you don’t understand what I mean. Here’s a clip.
As you can see, I started at the side of the cave far from the camera, but when I walk to the right I gradually move to the other side because of the camera. And eventually I hit the wall close to the camera.

https://gyazo.com/947cbe761e9a43c78f6c403b6aa87ef4

First of all looks awesome. Secondly what you’re trying to do here is most likely gunna result in a custom character controller. Since the default controller determines movement vectors based on the camera cframe, you would either have to rewrite the default scripts or write your own which in my opinion is much easier. I can go into more detail on how to do that if you’d like.

1 Like

As for keeping the player moving on one axis, one way you can do this is rebind the keys inside of PlayerModule. You can find the script under your player’s PlayerScripts folder.

image

If you copy that into StarterPlayerScripts it will override the default one.

You can change the keybindings inside of Keyboard, which is under ControlModule.

--[[

Here, I'm just commenting out the bindings that we don't need. I've then changed
the 'forward' action to move the character left, and
 the 'backward' action to move 
the character right.

]]
	-- TODO: Revert to KeyCode bindings so that in the future the abstraction layer from actual keys to
	-- movement direction is done in Lua
	--ContextActionService:BindActionAtPriority("moveForwardAction", handleMoveForward, false,
	--	self.CONTROL_ACTION_PRIORITY, Enum.PlayerActions.CharcterLeft)
	--ContextActionService:BindActionAtPriority("moveBackwardAction", handleMoveBackward, false,
	--	self.CONTROL_ACTION_PRIORITY, Enum.PlayerActions.CharcterRight)
	ContextActionService:BindActionAtPriority("moveLeftAction", handleMoveLeft, false,
		self.CONTROL_ACTION_PRIORITY, Enum.PlayerActions.CharacterBackward)
	ContextActionService:BindActionAtPriority("moveRightAction", handleMoveRight, false,
		self.CONTROL_ACTION_PRIORITY, Enum.PlayerActions.CharacterForward)
	ContextActionService:BindActionAtPriority("jumpAction", handleJumpAction, false,
		self.CONTROL_ACTION_PRIORITY, Enum.PlayerActions.CharacterJump)

Then, you can manipulate the camera to stay on one axis. Something quick to demonstrate how you might go about that:

local CAMERA_OFFSET = Vector3.new(20, 5, 0)

local RunService = game:GetService("RunService")

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local camera = workspace.CurrentCamera

while camera.CameraType ~= Enum.CameraType.Scriptable do
	camera.CameraType = Enum.CameraType.Scriptable
end

local connection = RunService.RenderStepped:Connect(function()
	camera.CFrame = CFrame.new(
		character.HumanoidRootPart.Position + CAMERA_OFFSET, character.HumanoidRootPart.Position
	)
	return
end)

As for making the camera ‘smooth’, I would personally do that with springs. I made a post before about how you could do this, and there are also resources to help you:

1 Like

Every now and then I see a pretty epic use case for a system I overlooked, camera movement with Springs is definitely one of them. Although definitely not as outlandish as the last one I ran into where a guy was using Explosions to get a hit table for combat rather than doing a distance check or raycasting lol. Definitely gunna try this one.

2 Likes

I will try it out!
Thanks for pointing me in the right direction :slight_smile:

I gave you the solution because your option will work if you execute it, but I found another way to do it :slight_smile:

image
The solution was simple:
Changed the BodyGyro.MaxTorque from Vector3.new(math.huge, math.huge, math.huge) to Vector3.new(math.huge, 0, 0)
Thnx tho!