Custom Shift Lock Script w/out using shift lock

So I’m working on coding my own space ship sorta thing but I want the camera/mouse movement to be how it is when players are using shift lock without having to enable shift lock. Like a 3rd person view of first person in a way. Does anyone know how I’d go about doing this? I’ve looked around online for a bit but haven’t exactly found what I want. I’ve just run into people who would edit an old camera module that doesn’t exist anymore or change the MouseBehavior to LockCenter which was almost what i wanted but not exactly

2 Likes

Not sure if this helps, but maybe you could give this a try:

Hope this helps.

2 Likes

So what exactly are you trying to achieve? Is there something specific about your camera you’re looking for that isn’t being met when you use LockCenter?

2 Likes

Well the thing is when i tried to use LockCenter i just looped it in the script so it would stay locked in the center, the thing it’s missing is I want to be able to move the mouse and have it move the character as well like it does with shift lock on

Thanks for sharing it, I’ll check it out and let you know if it helps!

Oh, locking the mouse in the center isnt the only step, you’d have to lock the center and then use Mouse.Delta to turn the character.

local mouse = player:GetMouse()
local RunService = game:GetService('RunService')

Mouse.Delta returns [A vector2 of] how far the mouse has moved since the last rendered frame. you can use that to turn the camera and ship accordingly.

4 Likes

omg god bless u I got it working how I want now

1 Like

Is there any more description on how to do this? I can’t seem to figure it out

Since then, I’ve actually found 2 better ways to do this. I cant seem to find the documentation for Mouse.Delta, but this article as well as this one establishes the same thing. This is the updated reply since it seems like people are relying on it.

In the context action service, every bound function passes the state, name and object. For the mouse or thumbstick movement, the state will be Enum.UserInputState.Change

The InputObject holds all the info on the interaction. [Keycode, Position, Delta, State (redundant), and Type]. You can read through the links for a better understanding.

The Delta will return a vector3 how much the mouse (or joystick) has moved. There technically is a Z coordinate in Delta, but it will always be 0 unless its detecting VR movement. The X and Y coordinate, however, can be used and translated for whatever you want. the faster you move the mouse, the higher those coordinates will be. I think you can see where I’m going with this.

local Context = game:GetService("ContextActionService")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
wait(3)
print('starting')
--setup
local camera = game.Workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = CFrame.new((character:GetPrimaryPartCFrame().Position+Vector3.new(0,50,0)),character:GetPrimaryPartCFrame().Position)


local uis = game:GetService("UserInputService")
uis.MouseBehavior = Enum.MouseBehavior.LockCenter --when not in LockCenter, it will only fire when a mousebutton is down

local part = Instance.new("Part")
part.Parent = workspace
part.CFrame = character:GetPrimaryPartCFrame()*CFrame.new(0,0,-5)

local function E(Name,State,OBJ)-- Mouse movements will have the "Changed" state. OBJ has a library of this interaction
	if State == Enum.UserInputState.Change then --since its the mouse, it will.
		local Delta = OBJ.Delta --the input object contains the keycode, input state, delta (if mouse or controller) and the position [of the input]
		print(Delta)
		part.Position = part.Position+Vector3.new(-Delta.Y,0,Delta.X)
	end
end

Context:BindAction('MovePart',E,false,Enum.UserInputType.MouseMovement)

This sample [local]script moves the part around using context action service, if you’re confused, you can poke around with this script and try to understand it more. It was definitely hell for me to figure it out, so I hope this is a bit easier for you.

6 Likes