Howdy, I’m currently working on a game with PvE enemies are going to lock onto the player and generally rotate a good bit, however I want to avoid using BodyGyros so I started looking into how Shift Lock works, and I cant find anything on it.
Does anyone know how shiftlock works? like whats the exact code behind it? I have been trying to find the code in the Camera Scripts so I can replicate it in Enemies
-- We need to use the right vector of the camera after rotation, not before
local newLookCFrame: CFrame = self:CalculateNewLookCFrameFromArg(overrideCameraLookVector, rotateInput)
local offset: Vector3 = self:GetMouseLockOffset()
local cameraRelativeOffset: Vector3 = offset.X * newLookCFrame.RightVector + offset.Y * newLookCFrame.UpVector + offset.Z * newLookCFrame.LookVector
--offset can be NAN, NAN, NAN if newLookVector has only y component
if Util.IsFiniteVector3(cameraRelativeOffset) then
subjectPosition = subjectPosition + cameraRelativeOffset
end
I found this on line 122 in the “ClassicCamera” module
Im not entirely sure if this is what I’m looking for, if anyone has any Idea how ShiftLock rotates the player in the game engine it would be very appreciated
i’m pretty sure all it does is lock the mouse to the middle of the screen and then offsetting the camera, which helps in aiming, pvp or stuff like obbies
Yeah, I’m referring to the way that the players HumanoidRootPart is locked to the cameras orientation. I’m just wondering how it actually does it.
Right now I’m thinking if it just constantly updates the HumanoidRootParts Y rotation relative to the camera however I feel like there would be more jitter when rotating if it did that, Ideally the best way to find out is to find the actual code they use, I’m currently trying find the Movement scripts for the Roblox characters.
I’m trying to find the method ShiftLock uses to rotate the player character so that way I can use the same method to rotate NPCs without using BodyGyros
While possible this is what Shiftlock uses CFrame.LookAt() I’m trying to find how Shiftlock does it and if it does use this how it applies it. I tried to use this as a stand in and there seems to be this “jitter” I’ll tweak with it a bit more but if I cant get it to a point where its an equivalent to what shiftlock does I’ll keep digging through the CameraModule
EDIT: It occured to me that I should post the video of this “jitter” in effect
This was the code I was using originally just to test it, I thought it would be the same but I tried your code and it locks in perfectly, no jitter at all.
When I tried to make the enemy walk around and look at the player it wont move, I’m assuming this is because LookAt is updating the position every time its called not letting the Enemy move.
using an alignorientation might be your best bet. you could also run the code on the client instead of the server so it doesnt affect the enemies movement.
I have found a “Custom Shiftlock” module, they use a similar technique but it uses CFrame:Lerp
The enemy will jitter around when moving, Im hoping that if I can fix that everything will work fine.
Edit: entirely forgot to mention but like I said in the main post I’d rather keep BodyGyros and any Constraints out if this if possible.