generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: My math is off

Previous Thread :: Next Thread 
Xtreme101 is not online. 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 is not online. Xtreme101
Joined: 03 Jan 2009
Total Posts: 4385
02 Sep 2013 02:22 PM
Bump.
Report Abuse
Absurdism is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image