How i can limit cframe rotation?

I’ m making a turret and i wan’t to limit it rotation to something like 90 studs
i’ve tried searching on dev forum , but after four hours - nothing, anyone have any idea?

TweenService:Create(), You can use. and how to use “TweenService” when clicked on blue place? is explained. (I think you mean something like animation)

1 Like

i know i can use tween service, but i wan’t to limit angle, get angle beetween turret and target on one axis, next limit this angle to 90 studs, and then rotate

example of exactly what you are wanting? or code you are using to do the rotation so far?

i wan’t to get angle beetween two positions, one is turret position and seccond is target(player position) , i wan’t turret can’t rotate more than 90 studs

I don’t understand, do you have an example?

Here is a code

local delta = target.Position - model.Primary.Position -- model.primary is turret position

model.Primary.Tower.HingeConstraint.TargetAngle = math.deg(math.atan2(delta.Z,-delta.X))/-1

Okay, After testing i get this, it’s simple at test

local folder = script.Parent
local A = folder.A --- target
local T = folder.T --- turret, base something like that

local AP = A.Position
local TP = T.Position

local offset = AP - TP
local Angle = math.atan2(offset.Z,offset.X)

print(math.deg(Angle))

it prints angle beetween two positions, anyway thanks for help

Was that really the problem? (oh my head…) sorry bro good luck!

1 Like

This is only test, i try to make it on bigger scale

1 Like

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