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 » Scripters
Home Search
 

Re: Magnitude.

Previous Thread :: Next Thread 
Faisal1207 is not online. Faisal1207
Joined: 27 Dec 2013
Total Posts: 499
14 Oct 2015 02:36 PM
Anybody tell me how magnitude works, and how i can implement this.
In for example, how can i tell if player is in the magnitude of a certain part.
The wiki doesn't go too in depth, and they don't tell how you can implement it.


- "I say no because yes is overrated"
Report Abuse
Faisal1207 is not online. Faisal1207
Joined: 27 Dec 2013
Total Posts: 499
14 Oct 2015 02:43 PM
Bump.


- "I say no because yes is overrated"
Report Abuse
Immacularity is not online. Immacularity
Joined: 21 Jun 2014
Total Posts: 419
14 Oct 2015 02:48 PM
The simplest way to explain magnitude is to say it's a form of averaging between the X, Y, and Z coordinates. It's a member of Vector3. You can use it to find the distance between two parts (basically just (part1.Position-part2.Position).magnitude), or to measure velocity (like if you want to detect if a player is falling/walking without using ROBLOX's crappy Humanoid events)


http://www.roblox.com/--item?id=130759239
Report Abuse
Faisal1207 is not online. Faisal1207
Joined: 27 Dec 2013
Total Posts: 499
14 Oct 2015 02:50 PM
How would i do it so if a player is in a certain magnitude of a certain item, i then connect the function?

ie:

function plrInmag()
if -- plr is in the magnitude of my part then
-- do stuff

end


- "I say no because yes is overrated"
Report Abuse
rayk999 is not online. rayk999
Joined: 18 Feb 2011
Total Posts: 4705
14 Oct 2015 02:51 PM
"How would i do it so if a player is in a certain magnitude of a certain item"
lol.


Red Blossoms
Report Abuse
Faisal1207 is not online. Faisal1207
Joined: 27 Dec 2013
Total Posts: 499
14 Oct 2015 02:55 PM
;(


Red blossoms

See what i did there, eehh?
Report Abuse
Immacularity is not online. Immacularity
Joined: 21 Jun 2014
Total Posts: 419
14 Oct 2015 02:56 PM
Most people are dumb and use magnitude for this, and that's the first solution most people come up with. However, ROBLOX made a function that probably uses C# (which is more efficient than Lua) named DistanceFromCharacter exactly for that purpose.

Just do this (assuming Player and part are defined:

`````
if Player:DistanceFromCharacter(part.Position) <= 50 then
print'player is within 50 studs of part'
end
`````

http://www.roblox.com/--item?id=130759239
Report Abuse
Zaxerion is not online. Zaxerion
Joined: 09 Feb 2013
Total Posts: 2304
14 Oct 2015 02:57 PM
function ismag(torso,part,range)
if (part.Position-torso.Position).magnitude < range then
return true
else
return false
end
end
Report Abuse
Faisal1207 is not online. Faisal1207
Joined: 27 Dec 2013
Total Posts: 499
14 Oct 2015 02:58 PM
Thanks ;D!


- "I say no because yes is overrated"
Report Abuse
rayk999 is not online. rayk999
Joined: 18 Feb 2011
Total Posts: 4705
14 Oct 2015 03:04 PM
function ismag(torso,part,range)
local p = part.Position-torso.Position
local magSq = p.x^2+p.y^2+p.z^2
if magSq < range^2 then
return true
else
return false
end
end

Using math to accomplish this is better, since magnitude (and DistanceFromCharacter) use math.sqrt, which is a pretty slow function. We can simply square the range and compare it to the squared magnitude

Red Blossoms
Report Abuse
Zaxerion is not online. Zaxerion
Joined: 09 Feb 2013
Total Posts: 2304
14 Oct 2015 03:08 PM
thanks for letting me knok
Report Abuse
notfruit is not online. notfruit
Joined: 21 Sep 2012
Total Posts: 1386
14 Oct 2015 03:24 PM
https://www.khanacademy.org/math/precalculus/vectors-precalc

https://www.mathsisfun.com/algebra/vectors.html

treat yo self w/ these links
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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