I want to use the servo property in a hinge constraint to face my character, but I don’t know what to use for the comparison.
local target = game.Workspace:WaitForChild("Mantorok4866")
while true do
wait()
script.Parent.HingePart.HingeConstraint.TargetAngle = --not sure what to add here
end
the reason Im using this instead of CFrame is because I want the joint to only rotate on one axis instead of all of them when aiming.
you do look familiar, maybe we met on roblox or script helpers.
but I think I may need to make another question because I dont know how this is going to complete my needs, this question was made for a test model in the hopes that It would help me finish this:
the original plan was to use the hinges to hook up the gun as seen here, I wanted the gun to rotate along the cabin, and the cabin along the base. but a new problem arises and thats how its going to be controlled. im not sure if its a good idea to ask another topic on top of another, but for the sake of time I want to try:
along with CFrame is there a way for me to track the mouse and have the gun move around as the mouse moves around (FE of course).
if not then ill accept the provided response as it does answer the first question.
Im not sure if you played either but:
the manually controlled turrets in aegis reborn, or base wars. when the player moves their mouse the whole gun moves along with it.
its an awesome concept but what confuses me is how they can move the gun with the mouse
and still make changes to the server without exhausting remote events.
as the player moves their mouse, the gun will rotate up and down, while at the same time the cabin and gun will rotate sideways along the base, the base itself wont be rotating and the whole thing will be in one place.
the mouse is also locked in the center just like those other games too.
I actually did something quite similar w/ CFrame on this post:
However, if u want to use these fancy new objects…
I tried downloading the file you posted but I couldn’t find the HingeConstraint.
Personally I’ve never bothered to play around with these fancy new objects much.
After fiddling around with it for a while, I’ve figured out the jist of it.
Here’s the math if you’re interested:
This is my code
-- Wait for player to join game
repeat wait() until #game.Players:GetChildren() > 0
Player = game.Players:GetChildren()[1]
-- Wait for Player's character to load
if not Player.Character then
Player.CharacterAdded:Wait()
end
-- define some variables
Char = Player.Character
CharPart = Char:WaitForChild('HumanoidRootPart')
Hinge = script.Parent
RootPart = Hinge.Parent
while wait() do
-- define position of origin
HKpos = Vector2.new(RootPart.Position.X,RootPart.Position.Z)
-- define position of target
XYpos = Vector2.new(CharPart.Position.X,CharPart.Position.Z)
-- the ratio to get the triangle's width over the height
ratio = (XYpos.Y-HKpos.Y)/(XYpos.X-HKpos.X)
beta = math.atan(ratio) -- converting this to radians
-- turn it from radians into degrees
beta = beta*(180/math.pi)
print(beta)
Hinge.TargetAngle = -beta -- beta has to be negative so it points at you
end