seanb117
|
  |
| Joined: 03 Feb 2010 |
| Total Posts: 1020 |
|
|
| 30 Dec 2013 08:33 PM |
So I am working on a tool that points a turret towards the mouse using welds. It ALMOST works, it'll point to the mouse but it doesn't always do it. I hear people who made scripts that point your arm towards the mouse had the same issue, but I'm not sure how they fixed it. Code relevant to the issue: function move(m) moving = true while (moving) do wait(0.0001) local offset = (connector.Position - m.Hit.p) local direction = offset.Unit local angle = math.atan2(direction.Z, direction.X) + (math.pi/2) local angle2 = math.asin(direction.Y) weld.C0 = CFrame.new(weld.C0.p) * CFrame.Angles(0, angle, 0) weld2.C0 = CFrame.new(weld2.C0.p) * CFrame.Angles(angle2, 0, 0)
end end |
|
|
| Report Abuse |
|
|
seanb117
|
  |
| Joined: 03 Feb 2010 |
| Total Posts: 1020 |
|
|
| 30 Dec 2013 08:36 PM |
I meant this: function move(m) moving = true while (moving) do wait(0.0001) local offset = (connector.Position - m.Hit.p) local direction = offset.Unit local angle = math.atan2(direction.Z, direction.X) + math.pi local angle2 = math.asin(direction.Y) weld.C0 = CFrame.new(weld.C0.p) * CFrame.Angles(0, angle, 0) weld2.C0 = CFrame.new(weld2.C0.p) * CFrame.Angles(angle2, 0, 0)
end end
(math.pi was divided by 2 in the other one, didn't help at all) |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 30 Dec 2013 08:37 PM |
| How are you calling this? Mouse.Move? |
|
|
| Report Abuse |
|
|
seanb117
|
  |
| Joined: 03 Feb 2010 |
| Total Posts: 1020 |
|
|
| 30 Dec 2013 08:41 PM |
| When the tool is selected. So the turret automatically points towards the mouse. It works fine if on a axis, but if it's(the vehicle) is turned around, it does the inverse. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 30 Dec 2013 08:42 PM |
| try setting the position to the part itself, instead of C0.p |
|
|
| Report Abuse |
|
|
seanb117
|
  |
| Joined: 03 Feb 2010 |
| Total Posts: 1020 |
|
|
| 30 Dec 2013 08:50 PM |
| It sent the turret flying..and killed my character in the process. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 30 Dec 2013 08:53 PM |
I don't get this "weld.C0 = CFrame.new(weld.C0.p) * CFrame.Angles(0, angle, 0) weld2.C0 = CFrame.new(weld2.C0.p) * CFrame.Angles(angle2, 0, 0) "
You have 2 welds? and you want the second weld to aim up/down and the first to aim sideways? |
|
|
| Report Abuse |
|
|
seanb117
|
  |
| Joined: 03 Feb 2010 |
| Total Posts: 1020 |
|
|
| 30 Dec 2013 08:58 PM |
Weld2, the up/down one, works perfectly fine. The first weld only works when it's in a good position.
Feel free to follow me here to see what i mean: http://www.roblox.com/Vehicle-Testing-Place-place?id=128389060 |
|
|
| Report Abuse |
|
|
seanb117
|
  |
| Joined: 03 Feb 2010 |
| Total Posts: 1020 |
|
|
| 30 Dec 2013 09:05 PM |
| Oh and the welds are in two different brick, affecting two different bricks. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 30 Dec 2013 09:07 PM |
| It seems reversed, try removing the + math.pi |
|
|
| Report Abuse |
|
|
seanb117
|
  |
| Joined: 03 Feb 2010 |
| Total Posts: 1020 |
|
|
| 30 Dec 2013 09:12 PM |
| Thats the thing, if I do. The exact opposite happens. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 30 Dec 2013 09:16 PM |
| I'll try to help tomorrow i gotta go |
|
|
| Report Abuse |
|
|
seanb117
|
  |
| Joined: 03 Feb 2010 |
| Total Posts: 1020 |
|
| |
|