Xtreme101
|
  |
| Joined: 03 Jan 2009 |
| Total Posts: 4385 |
|
|
| 02 Sep 2013 02:18 PM |
I'm trying to change my Character's Right Shoulder's DesiredAngle property based on the mouse's position. At line 7 I'm using The Law of Cosine to create an angle based off of sides a, b, and c of a triangle. No matter what a, b, and c are, it theata ALWAYS returns math.pi/2. Any trig help?
ray = Ray.new(game.Players.LocalPlayer.Character.Head.Position, game.Players.LocalPlayer.Character.Head.CFrame.lookVector*999) part, pointA = game.Workspace:FindPartOnRay(ray, domain) a = (game.Players.LocalPlayer.Character.Head.Position - pointA).magnitude b = (game.Players.LocalPlayer.Character.Head.Position - mouse.Hit.p).magnitude c = math.sqrt(a^2 + b^2) theata = math.acos((a^2 + b^2 - c^2)/(2*a*b)) shoulders[2].DesiredAngle = math.rad(theata) |
|
|
| Report Abuse |
|
|
Xtreme101
|
  |
| Joined: 03 Jan 2009 |
| Total Posts: 4385 |
|
| |
|
Absurdism
|
  |
| Joined: 18 Jul 2013 |
| Total Posts: 2568 |
|
|
| 02 Sep 2013 02:26 PM |
Given that the ray, a and b values are correct, you're still not using the Law of Cosines correctly. Don't use arccosine. Also, it irritates me that you're misspelling 'theta,' but hopefully, this is intentional.
theata = (a^2 + b^2 - c^2)/(2*a*b) shoulders[2].DesiredAngle = math.rad(theata) |
|
|
| Report Abuse |
|
|
Xtreme101
|
  |
| Joined: 03 Jan 2009 |
| Total Posts: 4385 |
|
|
| 02 Sep 2013 02:32 PM |
Not sure how I began spelling theta wrong, but thanks. Also, I thought The Law of Cosine was
c^2 = a^2 + b^2 - 2*a*b*math.cos(C)
so
2*a*b*math.cos(C) + c^2 = a^2 + b^2 2*a*b*math.cos(C) = a^2 + b^2 - c^2 math.cos(C) = (a^2 + b^2 - c^2)/(2*a*b) C = math.acos((a^2 + b^2 - c^2)/(2*a*b))
? |
|
|
| Report Abuse |
|
|
Absurdism
|
  |
| Joined: 18 Jul 2013 |
| Total Posts: 2568 |
|
|
| 02 Sep 2013 02:41 PM |
| You are correct. However, sometimes, it works better when dealing with DesiredAngles. |
|
|
| Report Abuse |
|
|
Xtreme101
|
  |
| Joined: 03 Jan 2009 |
| Total Posts: 4385 |
|
|
| 02 Sep 2013 02:48 PM |
| Okay, but, no matter what theta becomes, DesiredAngle always appears to be 0. |
|
|
| Report Abuse |
|
|
Absurdism
|
  |
| Joined: 18 Jul 2013 |
| Total Posts: 2568 |
|
|
| 02 Sep 2013 02:51 PM |
| Try applying the formula in a different script, except plug in arbitrary yet trigonometrically-related values for a and b. |
|
|
| Report Abuse |
|
|
Xtreme101
|
  |
| Joined: 03 Jan 2009 |
| Total Posts: 4385 |
|
|
| 02 Sep 2013 02:57 PM |
| Actually, I it has something to do with how ROBLOX responds to the new DesiredAngle input, because when I print it just after setting it, it returns 0. Maybe if I shorten the number? |
|
|
| Report Abuse |
|
|