Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I get my lower hinge to track the player properly?

Asked by 5 years ago

I have a project I've been working on and I tried writing my own script for a turret that tracks the player when it gets near, although at the moment I have it look for me regardless of distance. So far I have the actual gun part rotating properly, but not the thing it's attached to. It's literally the same code except using the Y axis instead of the X axis since it's mounted sideways on a wall.

Here's my code:

01local turret = script.Parent
02local gunHinge = turret.GunBase.Base.Base2GunHinge
03local gunHingePos = gunHinge.Attachment0.WorldPosition
04local baseHinge = turret.WallMount.Mount.Base2WallHinge
05local baseHingePos = baseHinge.Attachment0.WorldPosition
06 
07local target
08 
09local function trackObject(object)
10    local gunHingeX = object.Position.X - gunHingePos.X
11    local gunHingeZ = object.Position.Z - gunHingePos.Z
12    local baseHingeY = object.Position.Y - baseHingePos.Y
13    local baseHingeZ = object.Position.Z - baseHingePos.Z
14    local ratio1 = gunHingeX/gunHingeZ
15    local ratio2 = baseHingeY/baseHingeZ
View all 23 lines...

Thanks in advance! :D

0
What do you mean by lower hinge and what exactly is the problem AlmostADemon 50 — 5y
0
I have turret I built. It uses Hinge Constraints. The top hinge works perfectly. The bottom hinge does not. Here's a GIF of said problematic turret: https://media.giphy.com/media/ZE57kO7sx1iHd7wegy/giphy.gif acer1102 97 — 5y

Answer this question