KLGA
|
  |
| Joined: 19 Apr 2014 |
| Total Posts: 2571 |
|
|
| 12 Jun 2016 11:19 PM |
constantly check whether or not any player is within 10 units of a part,
here's my way, i'm not really liking the loop in my code :( can anybody think of a better method?
while wait() do for i,v in pairs(chrs) do --predefined list of characters if (chr.Torso.Position - Center.Position).magnitude <= 10 then print("my dude is in range!") end end end |
|
|
| Report Abuse |
|
|
KLGA
|
  |
| Joined: 19 Apr 2014 |
| Total Posts: 2571 |
|
|
| 12 Jun 2016 11:20 PM |
| made a mistake, oops, don't point it out, still looking for better way though |
|
|
| Report Abuse |
|
|
KLGA
|
  |
| Joined: 19 Apr 2014 |
| Total Posts: 2571 |
|
| |
|
|
| 12 Jun 2016 11:55 PM |
| Yeah do you really need to check the position of player 30 times a second? |
|
|
| Report Abuse |
|
|
iiEssence
|
  |
| Joined: 18 Jun 2014 |
| Total Posts: 3467 |
|
|
| 13 Jun 2016 12:13 AM |
| You could have a Vector3 value thats linked to the position of the character and use .Changed on that value. |
|
|
| Report Abuse |
|
|
Aethex
|
  |
| Joined: 16 Oct 2011 |
| Total Posts: 2193 |
|
|
| 13 Jun 2016 12:18 AM |
| Could also just put an invisible hit-box around that part, and then use the Touched event to see when a player is in range. |
|
|
| Report Abuse |
|
|
Syntropy
|
  |
| Joined: 16 Mar 2009 |
| Total Posts: 2272 |
|
|
| 13 Jun 2016 12:24 AM |
| I'm using the same method in my game and it's fine. ^ Touched events are too glitchy and unreliable. |
|
|
| Report Abuse |
|
|
Aethex
|
  |
| Joined: 16 Oct 2011 |
| Total Posts: 2193 |
|
|
| 13 Jun 2016 12:31 AM |
@Syntropy A stationary object running the Touched event? It's not glitchy nor unreliable. If this were actually the case, then all of those obbies with kill bricks would be terribly easy to beat. It's also even more likely to register considering the fact that, if large enough, the event will register for each individual limb on the character. I'm sure at least one would activate the Touched event.
If it's just one repeated loop to check for this, fine, but if you ever want to increase that amount, good luck. Try running code with a hundred simultaneous loops running to see if any character in the game is close to each and every part. The more players that joining will make it even worse. |
|
|
| Report Abuse |
|
|
Syntropy
|
  |
| Joined: 16 Mar 2009 |
| Total Posts: 2272 |
|
|
| 13 Jun 2016 12:40 AM |
When I tested it I had it check only for a part named torso. When it touches I print touch. When "TouchEnded" I print touchended. I take a single step in the region and get this in the output:
Touch TouchEnded Touch TouchEnded Touch
I lightly tap forward again:
TouchEnded Touch TouchEnded
This time the script is leaving off in the touch ended event and my character is still within the region. And yes I tried debouncing. |
|
|
| Report Abuse |
|
|
Aethex
|
  |
| Joined: 16 Oct 2011 |
| Total Posts: 2193 |
|
|
| 13 Jun 2016 12:47 AM |
I have no idea how you tested that, please post the code. I created a somewhat large part and used this:
script.Parent.Touched:connect(function(hit) if hit.Name == "Torso" then print("touched"); end end)
script.Parent.TouchEnded:connect(function(hit) if hit.Name == "Torso" then print("touchended"); end end)
--
It only printed that it was touched once while walking in, and then only printed touchended once when walking out. It continued to work fine no matter what I did while inside of this part. It didn't matter if I slowly moved out with MouseLock while half of my Torso still remained it, it worked fine. I am unable to replicate your results, please help me to. |
|
|
| Report Abuse |
|
|