|
| 16 Jan 2013 09:57 PM |
Ok well I am recreating a crossbow and I am refrencing a FM one to find out what I need to do and this is the firing function which is later called when the mouse is hit.
function fire(v)
local vCharacter = Tool.Parent
local vPlayer = game.Players:playerFromCharacter(vCharacter) Tool.Parent.Torso["Right Shoulder"].DesiredAngle = 3 --moves your arm as if firing.
local missile = Tool.Bolt:Clone()
-- find firing direction
local v1 = -Tool.Bolt.CFrame.lookVector.unit local v2 = v.unit
local dot = (v1.x * v2.x) + (v1.y * v2.y) + (v1.z * v2.z) local ang = math.acos(dot)
-- test if in cone if (ang < 3.14 / 8) then
else end
Please explain to me what all this is doing? (I know it is finding the fire direction) I don't understand the local dot = ? and I have never dealt with math.acos |
|
|
| Report Abuse |
|
|
| |
|
MrChubbs
|
  |
| Joined: 14 Oct 2010 |
| Total Posts: 4969 |
|
|
| 16 Jan 2013 11:03 PM |
| math.acos is the arc-cosine function. |
|
|
| Report Abuse |
|
|
MrChubbs
|
  |
| Joined: 14 Oct 2010 |
| Total Posts: 4969 |
|
|
| 16 Jan 2013 11:04 PM |
| So as that would imply it is essentially solving a triangle. |
|
|
| Report Abuse |
|
|
|
| 17 Jan 2013 04:35 AM |
| I'm not sure what dot is myself but acos or cos-1 also known as arccosine, is used in solving an angle, the angle is then later uses it in an expression, it checks whether if the angle is smaller than 3.14, in other words mathematical pi. Pi is also 180 degrees in radians, another form of unit to measure angles. I would assume that it is checking if the angle is smaller than 22.5 degrees,(pi/8 = 180/8 = 22.5). Though I'm not sure why it checks if it is smaller than that degree though as I am not too sure what dot does at the moment. |
|
|
| Report Abuse |
|
|
|
| 17 Jan 2013 07:11 AM |
| Oh I found out, dot, or dot product, used in this equation, just finds out the cosine of the angle that is between the two parts, just some complicated stuff. It can also calculate other things but if you'd like to find out more search on google or go onto wikipedia and find Dot Product. |
|
|
| Report Abuse |
|
|