So I got Sofloan to build me a mini-tank for my upcoming game Disaster Island and you can see it here:
Isn’t it glorious?
So anyways, I’m scripting it to make it into a intelligent killing machine with advanced pathfinding, explosive shells, etc. But I’m currently having trouble with one small part of the tank’s looking mechanics, the top part of the tank or the head is meant to turn to the left and right and the nozzle is meant to look up and down at it’s target. At the moment I have 2 hinge constraints set up to do just that and they work perfectly (using servo type). The problem is scripting their target angles in order to look at the tank’s target. My first attempt worked only when the tank’s rotation is at 0,0,0 and whenever it’s at a different rotation the results are inaccurate to say the least.
local lookCF = CFrame.new(verticalAim.Position, Torso.Position)
local X, Y, Z = lookCF:toEulerAnglesXYZ()
verticalHinge.TargetAngle = -math.deg(X)
horizontalHinge.TargetAngle = -math.deg(Y)
So I was wondering if you guys could come up with a way to make the top part turn left and right in order to face the target player and have the nozzle turn up and down to face the player’s vertical position at all rotations. I’m stumped so I hope one of you have an idea of what to do, I’m assuming it’ll involve some math I have no knowledge of… or it might be an easy solution that I just didn’t think of. Either way, thanks for the help