Arkose
|
  |
| Joined: 26 May 2013 |
| Total Posts: 745 |
|
|
| 17 Aug 2013 05:05 AM |
What is the most efficient way to have something happen when a player is close enough to an object? I do not want to be looping through the player list and checking their distance from this object, as there will be probably 15 or 20 different objects, and I feel that would cause a lot more lag.
Any replies are very much appreciated. |
|
|
| Report Abuse |
|
|
Cakins
|
  |
| Joined: 23 Jul 2009 |
| Total Posts: 307 |
|
|
| 17 Aug 2013 05:07 AM |
| Depends; are the objects stationary? Are the players in constant motion? |
|
|
| Report Abuse |
|
|
Arkose
|
  |
| Joined: 26 May 2013 |
| Total Posts: 745 |
|
|
| 17 Aug 2013 05:07 AM |
| Players are in constant motion, objects are stationary. Thank you for the quick reply. |
|
|
| Report Abuse |
|
|
|
| 17 Aug 2013 05:08 AM |
| Well you may not want to loop through the player list, but you will always have a distance when working with stuff like this, if you are completely against looping through the player list, use raycast. |
|
|
| Report Abuse |
|
|
Cakins
|
  |
| Joined: 23 Jul 2009 |
| Total Posts: 307 |
|
|
| 17 Aug 2013 05:11 AM |
I can think of three ways of doing it, ranging from easy to hard, though also ranging from inefficient to efficient.
Check ranges at all times position relative to players, rather than player's position relative to objects.
Create a field of parts in some manner around the stationary parts that would enable .Touched to positioning when things get close.
Using raycasting. |
|
|
| Report Abuse |
|
|
Arkose
|
  |
| Joined: 26 May 2013 |
| Total Posts: 745 |
|
|
| 17 Aug 2013 05:12 AM |
| Yes I could do that. Also I have no been on roblox for quite an amount of time, so I am not aware of recent updates. |
|
|
| Report Abuse |
|
|
Arkose
|
  |
| Joined: 26 May 2013 |
| Total Posts: 745 |
|
|
| 17 Aug 2013 05:16 AM |
The second option is what I was thinking of doing. I am not very familiar with ray casting, but essentially I would cast a ray from the character's lets say torso, to the object, and then measure the distance of that ray?
But isn't that essentially the same things as just looping through the players and calculating the distance between the object and the player?
Sorry I am a bit of a beginner, and I require a bit more explanation. |
|
|
| Report Abuse |
|
|
|
| 17 Aug 2013 05:18 AM |
| No, you would make a ray wherever you want, then use the method findpartonray to see if anything touches the ray, then use conditions to see if it is a player. |
|
|
| Report Abuse |
|
|
Saodo
|
  |
| Joined: 26 Jul 2011 |
| Total Posts: 1206 |
|
| |
|
| |
|
|
| 17 Aug 2013 05:19 AM |
| @ark depending on how you do it, your raycasting idea would be less laggier. |
|
|
| Report Abuse |
|
|
Arkose
|
  |
| Joined: 26 May 2013 |
| Total Posts: 745 |
|
|
| 17 Aug 2013 05:21 AM |
| He was referring to me. Yes I understand what I have to do with the ray casting , thank you for the replies everyone. |
|
|
| Report Abuse |
|
|