Pengu8
|
  |
| Joined: 27 Apr 2008 |
| Total Posts: 6974 |
|
|
| 06 Mar 2015 06:43 AM |
Little help here, help me find/display the angle of the projectile of my potato cannon. The script does it automatically, however I do not have much experience with lua to know where I can find the computed angle. I'm also not very good at math either. This is for my physics presentation (Due by the 15th) so whoever helps me get the answer will get credit at the end of the video! yay! :P
I post the important parts where I believe the angle may reside [replace the numbers in the word photo...]: i1214.ph0t0buck3t(dot)com//albums/cc499/miibunny/script1.png and...? i1214.[ph0t0buck3t](dot)com//albums/cc499/miibunny/script2.png (The reason for all the _G.s is because I was desperately trying to print what the cannon calculates on to the Output window to see if I magically end up finding the angle. I also needed _G.s for my velocity adjuster GUI.) Most of the printing doesn't give me the angle in degrees [but I haven't tried all the values on the Output yet] So it looks like I have to convert them? I'm not sure. Not much experience here in lua; qq
If you were wondering, the equations are on wikipedia under the name (can't post direct links on this thread) Trajectory_of_a_projectile
I don't know if it is using Angle \theta required to hit coordinate (x,y) or Angle of reach. (too lazy to look back again, it's REALLY late here and I'm tired).
All help is appreciated. Thanks. |
|
|
| Report Abuse |
|
|
ianfulton
|
  |
| Joined: 12 Apr 2011 |
| Total Posts: 98 |
|
|
| 06 Mar 2015 07:13 AM |
| Sorry. This is too confusing. .-. |
|
|
| Report Abuse |
|
|
Pengu8
|
  |
| Joined: 27 Apr 2008 |
| Total Posts: 6974 |
|
|
| 06 Mar 2015 07:52 AM |
?In what sense? The physics? It's basic kinematics....
Bump |
|
|
| Report Abuse |
|
|
HexC3D
|
  |
| Joined: 30 Jun 2012 |
| Total Posts: 10044 |
|
| |
|
HexC3D
|
  |
| Joined: 30 Jun 2012 |
| Total Posts: 10044 |
|
|
| 06 Mar 2015 10:10 AM |
| Do you have the initial height and distance of the projectile? |
|
|
| Report Abuse |
|
|
HexC3D
|
  |
| Joined: 30 Jun 2012 |
| Total Posts: 10044 |
|
|
| 06 Mar 2015 10:17 AM |
If so.. local g = 196.2 local v = -- You have the velocity right Local angle = math.atan (v^2+-math.sqrt (v^4 - x^2 + 2yv^2))/g×x |
|
|
| Report Abuse |
|
|
HexC3D
|
  |
| Joined: 30 Jun 2012 |
| Total Posts: 10044 |
|
|
| 06 Mar 2015 10:22 AM |
x = -- Distance or v^2/g y = -- hope you solved the maximum height of the projectile already. |
|
|
| Report Abuse |
|
|
HexC3D
|
  |
| Joined: 30 Jun 2012 |
| Total Posts: 10044 |
|
|
| 06 Mar 2015 10:25 AM |
| To make sure the lua operator understands, change '2yv' to 2×y×v. |
|
|
| Report Abuse |
|
|
HexC3D
|
  |
| Joined: 30 Jun 2012 |
| Total Posts: 10044 |
|
|
| 06 Mar 2015 10:31 AM |
Theta is equal to the angle, the angle should reach the coordinates(x, y) Though my equation might be flawed somewhere.
|
|
|
| Report Abuse |
|
|
|
| 06 Mar 2015 10:58 AM |
^^
You need more than just that to correctly make it work in ROBLOX. Theoretical answers can be simply found on Wikipedia.
Here's a working example model (+ source code)
http://www.roblox.com/Calculate-Launch-Angle-Example-item?id=223639521
local pa, pb, project = workspace.Model.PointA,workspace.Model.PointB,workspace.Model.Projectile; local PBPos, PAPos = pb.Position - Vector3.new(0,pb.Position.Y,0), pa.Position - Vector3.new(0,pa.Position.Y,0); local Distance = (PBPos - PAPos).magnitude local InitialVelocity = 200 local Gravity = 196.2 local YDifference = ((pb.Position.Y - pa.Position.Y)) print(YDifference); local Determinant = (InitialVelocity ^ 4) - (Gravity * ((Gravity*(Distance^2)) + (2*YDifference*(InitialVelocity^2)))); local Root = math.sqrt(Determinant) local Theta = math.atan( ((InitialVelocity ^ 2) + Root) / (Gravity*Distance) )
-- Launch part project.Anchored = true; project.CanCollide = false;
-- Find length of opposite side of triangle (height adjustment) local LengthOfOpposite = math.tan(Theta) * Distance; print("Height adjustment: " .. LengthOfOpposite); project.CFrame = CFrame.new(pa.Position, pb.Position + Vector3.new(0,LengthOfOpposite,0)) project.Anchored = false; project.Velocity = project.CFrame.lookVector * InitialVelocity |
|
|
| Report Abuse |
|
|
HexC3D
|
  |
| Joined: 30 Jun 2012 |
| Total Posts: 10044 |
|
|
| 06 Mar 2015 12:40 PM |
You just applied the equation in rbx.lua, oh btw Dr this requires basic knowledge of trigonometry am I right.. I can't type code on a phone, so putting down the theoretical equation is much interesting. |
|
|
| Report Abuse |
|
|
HexC3D
|
  |
| Joined: 30 Jun 2012 |
| Total Posts: 10044 |
|
|
| 06 Mar 2015 12:41 PM |
The auto correct on this phone is harsh.
*Much more easier |
|
|
| Report Abuse |
|
|
anaIyze
|
  |
| Joined: 29 May 2014 |
| Total Posts: 2048 |
|
| |
|
maxomega3
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 10668 |
|
|
| 06 Mar 2015 12:46 PM |
| I don't recall anyone named "much" posting here |
|
|
| Report Abuse |
|
|
anaIyze
|
  |
| Joined: 29 May 2014 |
| Total Posts: 2048 |
|
|
| 06 Mar 2015 01:02 PM |
| Trying to be smart with me? |
|
|
| Report Abuse |
|
|
|
| 06 Mar 2015 02:10 PM |
"You just applied the equation in rbx.lua"
Yes... I know, but just as I said, it's more than just applying it to ROBLOX. You need to do a bit of vector mathematics to get a situation where the equation will even work. Just knowing that equation is only half the battle. |
|
|
| Report Abuse |
|
|
HexC3D
|
  |
| Joined: 30 Jun 2012 |
| Total Posts: 10044 |
|
|
| 06 Mar 2015 02:34 PM |
| Not bad if you just in algebra 1 , right? |
|
|
| Report Abuse |
|
|
|
| 06 Mar 2015 02:35 PM |
Well, I mean anybody can go to Wikipedia and find the equation :P
Now, if you can describe the derivation of the equation or the theory behind the law in Physics which dictates that equation, then yes. That wouldn't be bad for Alg I |
|
|
| Report Abuse |
|
|
HexC3D
|
  |
| Joined: 30 Jun 2012 |
| Total Posts: 10044 |
|
| |
|
HexC3D
|
  |
| Joined: 30 Jun 2012 |
| Total Posts: 10044 |
|
|
| 06 Mar 2015 02:41 PM |
I forced myself to at least learn the basics of trig. When I looked at formula , it wasn't too bad.
At least now I know how to calculate the angle, time, distance of a projectile. plus I'm pretty sure I can derive some of the concepts. |
|
|
| Report Abuse |
|
|
|
| 06 Mar 2015 02:42 PM |
Do you? Do you know what I'm doing in the later part of my code I posted when I do the 'finding' of the opposite side of the triangle and _why_ I do it?
|
|
|
| Report Abuse |
|
|
HexC3D
|
  |
| Joined: 30 Jun 2012 |
| Total Posts: 10044 |
|
|
| 06 Mar 2015 02:50 PM |
| Correct me if im wrong but it has something to do with find in the initial or begging height of the projectile, either that or calculating the the hieght when it loses velocity. |
|
|
| Report Abuse |
|
|
HexC3D
|
  |
| Joined: 30 Jun 2012 |
| Total Posts: 10044 |
|
| |
|
|
| 06 Mar 2015 02:55 PM |
Nah, not the initial height of the projectile, but the initial angle.
See, we might have found the launch angle, denoted as "Theta" in my code, but how do you apply that to our situation here? We need the object to point at the target, CFrame.new(Start, TargetLookAt), but we also need it to be angled upwards.
Well, we have the angle it needs to be tilted, and the distance between the two points. Problem is, we can't just change the rotation of the part. Due to Euler Angles being wack, if you try that (which I did) it will adjust the entire orientation incorrectly. So, we adjust the TargetLook at (in the CFrame.new() above) to be higher on the Y axis.
If you remember SOHCAHTOA, you'll notice we have the angle and the Adjacent data, but we need the Opposite (TOA). So we do this:
Tan(Theta) = Opp/Adj Tan(Theta) * Adj = Opp
Now we've found the height of the right-triangle and the height to adjust the TargetLookAt by. That's why I add it to the Y axis of the vector. |
|
|
| Report Abuse |
|
|
HexC3D
|
  |
| Joined: 30 Jun 2012 |
| Total Posts: 10044 |
|
|
| 06 Mar 2015 03:04 PM |
How could I forget SOHCAHTOA or at least the TOA part. I learn something new everyday, you were finding the y axis or the hieght of the triangle so you you could adjust the projectile launch angle.
|
|
|
| Report Abuse |
|
|