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: In cone function

Previous Thread :: Next Thread 
XlegoX is not online. 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 is not online. 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
Aeuronatics is not online. Aeuronatics
Joined: 08 Oct 2008
Total Posts: 7122
10 Apr 2009 07:37 PM
kkthxbye
Report Abuse
larryboylover92 is not online. larryboylover92
Joined: 20 Jul 2008
Total Posts: 4211
10 Apr 2009 07:37 PM
Cool, thanks!
Report Abuse
XlegoX is not online. 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
level140roblox is not online. level140roblox
Joined: 08 Jun 2008
Total Posts: 9577
10 Apr 2009 08:04 PM
I don't think anyone has ever posted a script without meelo criticizing it. Evar!
Report Abuse
Meelo is not online. 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 is not online. 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 is not online. Uploaders
Joined: 24 Oct 2008
Total Posts: 472
10 Apr 2009 08:22 PM
Ohhh Ok.
Report Abuse
dwighterz is not online. dwighterz
Joined: 29 Mar 2008
Total Posts: 5057
10 Apr 2009 08:32 PM
Where do you guys even learn this stuff?
Report Abuse
kisamebeast is not online. kisamebeast
Joined: 17 Jan 2008
Total Posts: 3086
10 Apr 2009 08:32 PM
Depends.
Nice script Xleego, though I don't know how this would be useful lol
Report Abuse
Tutorial09 is not online. Tutorial09
Joined: 10 Apr 2009
Total Posts: 83
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 is not online. MicroUser
Joined: 29 Mar 2009
Total Posts: 3601
10 Apr 2009 09:06 PM
[ Content Deleted ]
Report Abuse
Tutorial09 is not online. Tutorial09
Joined: 10 Apr 2009
Total Posts: 83
10 Apr 2009 09:07 PM
Variable,Script. Same thing,I am to help. Not to post.



~09~
Report Abuse
MicroUser is not online. MicroUser
Joined: 29 Mar 2009
Total Posts: 3601
10 Apr 2009 09:08 PM
[ Content Deleted ]
Report Abuse
Tutorial09 is not online. Tutorial09
Joined: 10 Apr 2009
Total Posts: 83
10 Apr 2009 09:14 PM
Yes.




~09~
Report Abuse
MicroUser is not online. MicroUser
Joined: 29 Mar 2009
Total Posts: 3601
10 Apr 2009 09:17 PM
[ Content Deleted ]
Report Abuse
Tutorial09 is not online. Tutorial09
Joined: 10 Apr 2009
Total Posts: 83
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 is not online. MicroUser
Joined: 29 Mar 2009
Total Posts: 3601
10 Apr 2009 09:20 PM
[ Content Deleted ]
Report Abuse
MicroUser is not online. MicroUser
Joined: 29 Mar 2009
Total Posts: 3601
10 Apr 2009 09:20 PM
[ Content Deleted ]
Report Abuse
Tutorial09 is not online. Tutorial09
Joined: 10 Apr 2009
Total Posts: 83
10 Apr 2009 09:21 PM
Well im not a "Master" at scripting,im more of a techinal errors helper.
Report Abuse
XlegoX is not online. 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
Tutorial09 is not online. Tutorial09
Joined: 10 Apr 2009
Total Posts: 83
10 Apr 2009 09:23 PM
Er,Thanks.
Im a helper,thats why I was created :P


~09~
Report Abuse
Robogator is not online. Robogator
Joined: 27 Aug 2008
Total Posts: 16694
15 Apr 2009 04:43 PM
Anyone else notice the 73333331?
Report Abuse
larryboylover92 is not online. larryboylover92
Joined: 20 Jul 2008
Total Posts: 4211
15 Apr 2009 04:50 PM
Nope...
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