MM233
|
  |
| Joined: 19 Jun 2008 |
| Total Posts: 925 |
|
|
| 02 Jan 2012 01:20 PM |
I'm making a turret on a vehical using a Motor6D. I need full 360* rotation. It is controlled with a hopperbin. Script:
local tool = script.Parent local HCv = tool.HCValue local hingeA = HCv.Value:findFirstChild("HingeA1")
tool.Selected:connect(function (mouse) while wait(0.1) do local guideD = HCv.Value.Handle.CFrame.lookVector local a = ((hingeA.Position + guideD) - mouse.Hit.p).magnitude local b = ((hingeA.Position - guideD) - mouse.Hit.p).magnitude local A = mouse.Hit.p.Z - hingeA.CFrame.Z local B = (mouse.Hit.p - hingeA.Position).magnitude if aa <= ba then hingeA.Motor6D.DesiredAngle = math.asin(A/B) * -1 elseif a >= b then hingeA.Motor6D.DesiredAngle = math.asin(A/B) - 3.125 end end end)
tool.Deselected:connect(function () hingeA.Motor6D.DesiredAngle = 0 end)
The script works, but when the turret cannot rotate all the way through on the right side. This is because, when the mouse passes to the rear of the turret, the value becomes a negative number (After reaching about 1.3) and the Motor6D rotates back to 0 and then through to negative numbers to get to the new position. I need it to go directly from the aproximate 1.3 limit into the negative numbers, with out rotating all the way back around. |
|
|
| Report Abuse |
|
|
MM233
|
  |
| Joined: 19 Jun 2008 |
| Total Posts: 925 |
|
|
| 02 Jan 2012 02:31 PM |
| Bawmp. Am I being ignored again? o_O I thought this would be within the forum rules... |
|
|
| Report Abuse |
|
|
|
| 02 Jan 2012 02:36 PM |
| Just do something to convert the destination rotation to a number which doesnt go around (like if its negative, make it a positive value that makes the same rotation or something) |
|
|
| Report Abuse |
|
|
MM233
|
  |
| Joined: 19 Jun 2008 |
| Total Posts: 925 |
|
|
| 02 Jan 2012 02:39 PM |
| I thought I had figured that out. One full rotation is 6.3. So subtract the current number from 6.3 and multiply by -1 and there you go. Only when I tried it, my turret spazzed. ^-^ I may have gotten something wrong... |
|
|
| Report Abuse |
|
|
Oysi
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
| |
|
MM233
|
  |
| Joined: 19 Jun 2008 |
| Total Posts: 925 |
|
|
| 02 Jan 2012 03:02 PM |
| I'm not having problems finding the right angle, but the turret has a blind spot on the right side. I need to keep the angle under 6.3 (or -6.3) at all times to keep 0 within one rotation. If its hard to understand my problem, go to my place and climb into the seat on the right side of my Hovercraft. Then select the tool and place your mouse near the front of the hovercraft. Then slowly move your mouse around the right side the the back in a half circle, and you should see the problem. |
|
|
| Report Abuse |
|
|