Choppy Lock On system [SOLVED]

Hi, I’ve been recently doing a combat system focused punch and kick mixup combos and skills, with a lock on system to make it easier to everyone
the problem is, ive been trying to make a smooth lock on system for a long time now and all my solutions were bad or just didnt work

the one that im currently using and the one i have faith that will work is one that…

  • searches for close players on a local script
  • if found, sets the closest enemy as a value in a ObjectValue (it does that by sending it to the server, so its set on the server, and not on the client)
  • after setting the ObjectValue, a renderstepped loop checks if the value is nil and, updates its cframe to face the enemy thats on the ObjectValue

heres the script

LockOn = RunService.RenderStepped:Connect(function()
	for i,player in pairs(Players) do
		if player.Character and player.Character.CharacterStats and player.Character.HumanoidRootPart.Anchored == false and player.Character.CharacterStats.Target.Value ~= nil then
			local Character = player.Character
			if Character.CharacterStats.Target.Value ~= nil then
				local EnemyRoot = Character.CharacterStats.Target.Value.HumanoidRootPart
				local Root = Character.HumanoidRootPart
				
				local lookAt = Vector3.new(EnemyRoot.Position.X, Root.Position.Y, EnemyRoot.Position.Z)
				Root.CFrame = (Root.CFrame:Lerp(CFrame.new(Root.Position, lookAt), 0.6))
			end
		end
	end
end)

this script is located on StarterPlayerScripts, so every player has it and stuff ( its also used for effects replication and sounds)

basically, its still really choppy and i have some clips of players seeing it by other perspectives. On your client, your movements look smooth, but the others are really, REALLY laggy.

i dont know if theres a easy fix for this or not, im thinking about straight up removing lock on because its been giving me so many headaches and i just cant get anything to work
im open to entire new lock on systems as long as it looks good on every client, thanks!

1 Like

its because you’re setting the rootparts’ cframe on the client and roblox’s replication doesn’t handle that well. i would just set the camera’s cframe instead of the root itself, and orient the character using another method like bodygyro(make sure you instance it on the server)

2 Likes

I was doing that before but because of the camera offset it didnt line up and you basically attacked to the side of your enemy when too close
is there a way to somehow make it work? if not, how do i do this body gyro thing?

if the camera is shift locked to the character, then you can instance a bodyGyro in the rootpart and set it’s cframe to the cframe.lookat(me,enemy), but make sure you set the maxtorque to like (0,9999,0) so you only turn on the right axis(also im pretty sure you can just set the cframe on the client)

1 Like

Ill try that out, gimme some minutes

you could fork your own custom version of roblox’s playermodules to allow you set the UserGameSettings.RotationType to CameraRelative, which is what shiflock uses to set the humanoid’s direction to face the camera

1 Like

works like a charm! thank you so much!

1 Like

id do that, but the camera offset makes so you attack at a weird angle and just makes you miss every attack, but now i found the body gyro method and it works really well, thanks for the help tho!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.