XlegoX
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 14955 |
|
|
| 10 Apr 2009 07:35 PM |
function IsInCone(part0, part1, angle) local dir0 = part0.Position+part0.CFrame.lookVector*(part0.Position - part1.Position).magnitude if ((part1.Position - dir0).magnitude/2) < math.sin(angle) * (part0.Position - part1.Position).magnitude then return true end return false end
Function determines if [part1] is in an [angle] degree cone of [part0]'s lookVector, a lot of people ask for it so I thought I'd make one and post it. |
|
|
| Report Abuse |
|
|
Meelo
|
  |
| Joined: 04 Jul 2008 |
| Total Posts: 14763 |
|
|
| 10 Apr 2009 07:37 PM |
O_o
But you can optimize that to
function IsInCone(part0, part1, angle) local dir0 = part0.Position+part0.CFrame.lookVector*(part0.Position - part1.Position).magnitude return ((part1.Position - dir0).magnitude/2) < math.sin(angle) * (part0.Position - part1.Position).magnitude end |
|
|
| Report Abuse |
|
|
| |
|
| |
|
XlegoX
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 14955 |
|
|
| 10 Apr 2009 08:03 PM |
Optimization isn't critical for stuff like that...
If I make something for the point of other people I don't optimize it, so that ti's more easily understanable.
simply putting "local game = game" at the start of a script does more than pretty much any other optimization =P |
|
|
| Report Abuse |
|
|
|
| 10 Apr 2009 08:04 PM |
| I don't think anyone has ever posted a script without meelo criticizing it. Evar! |
|
|
| Report Abuse |
|
|
Meelo
|
  |
| Joined: 04 Jul 2008 |
| Total Posts: 14763 |
|
|
| 10 Apr 2009 08:06 PM |
"simply putting "local game = game" at the start of a script does more than pretty much any other optimization =P"
Less indexing of _G? Makes sense. |
|
|
| Report Abuse |
|
|
XlegoX
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 14955 |
|
|
| 10 Apr 2009 08:09 PM |
Yes, it takes about 10 times as long when you index a global as with a local.
Since locals are stored by index in the stack, but globals are stored by thier actual identifer as a string, meaning every time you index them the environment must be iterated through. |
|
|
| Report Abuse |
|
|
Uploaders
|
  |
| Joined: 24 Oct 2008 |
| Total Posts: 472 |
|
| |
|
dwighterz
|
  |
| Joined: 29 Mar 2008 |
| Total Posts: 5057 |
|
|
| 10 Apr 2009 08:32 PM |
| Where do you guys even learn this stuff? |
|
|
| Report Abuse |
|
|
|
| 10 Apr 2009 08:32 PM |
Depends. Nice script Xleego, though I don't know how this would be useful lol |
|
|
| Report Abuse |
|
|
|
| 10 Apr 2009 09:03 PM |
local game = game
The function makes it easyier to script. Making a script is hard without using the Function local game = game |
|
|
| Report Abuse |
|
|
MicroUser
|
  |
| Joined: 29 Mar 2009 |
| Total Posts: 3601 |
|
| |
|
|
| 10 Apr 2009 09:07 PM |
Variable,Script. Same thing,I am to help. Not to post.
~09~ |
|
|
| Report Abuse |
|
|
MicroUser
|
  |
| Joined: 29 Mar 2009 |
| Total Posts: 3601 |
|
| |
|
| |
|
MicroUser
|
  |
| Joined: 29 Mar 2009 |
| Total Posts: 3601 |
|
| |
|
|
| 10 Apr 2009 09:18 PM |
The money script. A money script is a example of a variable. A variable is a item in a RP or a script. local game = game Is a variable,such as it is a part of a script.
~09~ |
|
|
| Report Abuse |
|
|
MicroUser
|
  |
| Joined: 29 Mar 2009 |
| Total Posts: 3601 |
|
| |
|
MicroUser
|
  |
| Joined: 29 Mar 2009 |
| Total Posts: 3601 |
|
| |
|
|
| 10 Apr 2009 09:21 PM |
| Well im not a "Master" at scripting,im more of a techinal errors helper. |
|
|
| Report Abuse |
|
|
XlegoX
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 14955 |
|
|
| 10 Apr 2009 09:22 PM |
"A variable is a keyword that is connected to a value stored in the CPU..."
That depends.
In Lua that's true of a Global Varaible, but local varaibles are stored by stack index, not a keyword |
|
|
| Report Abuse |
|
|
|
| 10 Apr 2009 09:23 PM |
Er,Thanks. Im a helper,thats why I was created :P
~09~ |
|
|
| Report Abuse |
|
|
Robogator
|
  |
| Joined: 27 Aug 2008 |
| Total Posts: 16694 |
|
|
| 15 Apr 2009 04:43 PM |
| Anyone else notice the 73333331? |
|
|
| Report Abuse |
|
|
| |
|