Turret Tracking Issue

Sorry to bug you again, but do you have any idea why this is doing this though?


local X, Y, Z = absoluteTurretCFrame:ToOrientation()
local X2, Y2, Z2 = absoluteTurretCFrame:ToEulerAnglesXYZ()
local ClampedY = math.clamp(Y,Y2 - 2,Y2 + 2)

Elsewise it works great and it correctly stops on angles.
Just this turning backwards things when standing on it may be problematic, oh and it doesn’t matter if your floating above it, as long as you’re standing above this area the clamp stops working correctly.

Can you post a GIF please? It is hard to tell what is going on there.

https://youtu.be/AxNv_os9u9o I’ll do you one better.

That video was kind of hard to tell what was going on too. xD Its good though, I can at least see what you are talking about now!

Can you post your new code now that you have made updates?

local absoluteTurretCFrame = CFrame.new(script.Parent.Body.TurretPos.Position, Players[i].Character.HumanoidRootPart.Position)

	local Test = isInAngleRange(script.Parent.HumanoidRootPart.CFrame.p, script.Parent.HumanoidRootPart.CFrame.LookVector, Players[i].Character.HumanoidRootPart.Position)



if Test then
local X, Y, Z  = absoluteTurretCFrame:ToOrientation()

local X2, Y2, Z2  = absoluteTurretCFrame:ToEulerAnglesXYZ()


local ClampedX = math.clamp(X,-0.2,0.2)



local ClampedY = math.clamp(Y,Y2 - 2,Y2 + 2)

script.Parent.Head:SetPrimaryPartCFrame(CFrame.new(absoluteTurretCFrame.p) * CFrame.fromOrientation(ClampedX,ClampedY,0))

else
	

	script.Parent.Head:SetPrimaryPartCFrame(script.Parent.Body.TurretPos.CFrame)
	
	
	
	end
	
end

(EXCUSE THE MESS ;o; it was a code warzone)



Both above images are from the Developer Hub page for CFrames


I think you may just need to reorganize your points like so;

CFrame.fromOrientation(ClampedY, ClampedX, 0)

Let me know what happens. good luck. :+1:t3:

image

Lmao, that doesn’t look right. :rofl:

trys to make tank turret function properly Tank: NECK SNAP SOUND

but in all seriousness, it works until that very specific spot in the middle is touched, then it goes full disco depending on where you walk. (Which I assume is the clamp stopping for some reason)

I can walk to its side, or its back without any issue.

I’m thinking the problem is with this part (revert that last change for sure lmao).

Yeah, I tested it a bit earlier and it seems the X clamp doesn’t give out, it’s the Y clamp that gives out (It still clamps correctly for X even when Y is crying)

Actually, when you are back there I am pretty sure it is not meeting the condition of the if statement to use the “Test” portion at all.

I think the problem is here:

Edit: I also think I am tired and confused lol, I think I need to go to bed… :sweat_smile:

1 Like

I had that for reseting the Cframe back to its original state, I can try removing it and see if it fixes itself.

Edit: Alright I can get that, I’m a bit tired too lmao, I’ll just work on other things and for now ignore the rave party.

Could be unrelated, but I noticed that image

tends to snap back into place while
image

pushes back when it gets too far

1 Like

Was experimenting around, it seems the clamp fails when it hits positive numbers, which the top is in the middle so it can hit those numbers for some reason on certain angles.

EDIT: I think its something to do with that angle code, because I removed the clamp and it still did this effect when standing right on it, but the clamp should’ve also stopped that.

FINALEDIT?: I seem to have fixed it, it was a piece of angle code that was missing a variable since it wasnt the mouse itself it was aiming at, very glitchy though but managable now.

1 Like

Yay!!

What is the behavior like now?

I had to add the Y angle into the mix for it to work, so it doesn’t like it when you jump right infront of it it will immediately return false, causing it to give up on its target doing that, its a better start though as now it doesn’t rave when you jump on it, I just need to find a tweak to allow it to look slightly higher.

Jumping a small distance away has no issue, I think it just needs some small tweaks, otherwise its fine now. Thank you.

Awesome, glad to hear that! Thanks for letting me know. If you have any more difficulties with this issue coming up, feel free to respond to me here (so I get a notification).

1 Like