|
| 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 |
|
|
|
| 14 Oct 2015 02:43 PM |
Bump.
- "I say no because yes is overrated" |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 14 Oct 2015 02:55 PM |
;(
Red blossoms
See what i did there, eehh? |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 14 Oct 2015 02:58 PM |
Thanks ;D!
- "I say no because yes is overrated" |
|
|
| Report Abuse |
|
|
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
|
  |
| Joined: 09 Feb 2013 |
| Total Posts: 2304 |
|
|
| 14 Oct 2015 03:08 PM |
| thanks for letting me knok |
|
|
| Report Abuse |
|
|
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 |
|
|