he_ro
|
  |
| Joined: 08 Jun 2013 |
| Total Posts: 634 |
|
|
| 07 Aug 2017 05:09 PM |
Whats the most efficient way to determine if a mouses target changed
|
|
|
| Report Abuse |
|
|
Thane_1
|
  |
| Joined: 08 Apr 2009 |
| Total Posts: 827 |
|
|
| 07 Aug 2017 05:10 PM |
| By using a loop and checking it's target. There is no other way. |
|
|
| Report Abuse |
|
|
he_ro
|
  |
| Joined: 08 Jun 2013 |
| Total Posts: 634 |
|
| |
|
|
| 07 Aug 2017 05:13 PM |
| I'd just use mouse.Move, and compare the last target with the current. |
|
|
| Report Abuse |
|
|
cabbler
|
  |
| Joined: 19 Jun 2015 |
| Total Posts: 735 |
|
|
| 07 Aug 2017 05:19 PM |
| mouse.Move is bad because it calculates either too much (mouse moving) or not enough (mouse still) |
|
|
| Report Abuse |
|
|
| |
|
he_ro
|
  |
| Joined: 08 Jun 2013 |
| Total Posts: 634 |
|
| |
|
cabbler
|
  |
| Joined: 19 Jun 2015 |
| Total Posts: 735 |
|
|
| 07 Aug 2017 07:39 PM |
| It's only better than a loop if the situation needing the connection is a few seconds long. noobs will end up lagging their clients. |
|
|
| Report Abuse |
|
|
Casualist
|
  |
| Joined: 26 Jun 2014 |
| Total Posts: 4443 |
|
|
| 07 Aug 2017 07:43 PM |
| Mouse.Moved probably isn't the way to go because the target can change if this move in-front of/or away from the mouse |
|
|
| Report Abuse |
|
|
|
| 07 Aug 2017 07:50 PM |
Just use a loop... I don't know why people think using loops are bad and laggy. It is, but only if you overuse it (which is hard to reach unless you are doing something wrong).
|
|
|
| Report Abuse |
|
|
|
| 07 Aug 2017 07:56 PM |
http://wiki.roblox.com/index.php?title=API:Class/Instance/GetPropertyChangedSignal
|
|
|
| Report Abuse |
|
|
he_ro
|
  |
| Joined: 08 Jun 2013 |
| Total Posts: 634 |
|
|
| 07 Aug 2017 08:02 PM |
unfortunately GetPropertyChangedSignal doesn't work for mouse
|
|
|
| Report Abuse |
|
|
|
| 07 Aug 2017 08:02 PM |
"unfortunately GetPropertyChangedSignal doesn't work for mouse"
really
that would have been a good solution
|
|
|
| Report Abuse |
|
|
he_ro
|
  |
| Joined: 08 Jun 2013 |
| Total Posts: 634 |
|
|
| 07 Aug 2017 08:05 PM |
it was one of the first things I tried haha
|
|
|
| Report Abuse |
|
|
Casualist
|
  |
| Joined: 26 Jun 2014 |
| Total Posts: 4443 |
|
|
| 07 Aug 2017 08:11 PM |
local player = game:GetService("Players").LocalPlayer local mouse = player:GetMouse() local last = mouse.Target local mouseTargetChanged = Instance.new("BindableEvent") game:GetService("RunService").Heartbeat:connect(function() if mouse.Target ~= last then last = mouse.Target mouseTargetChanged:Fire(last) end end) mouseTargetChanged.Event:connect(function(newTarget) print(newTarget) end) |
|
|
| Report Abuse |
|
|
cabbler
|
  |
| Joined: 19 Jun 2015 |
| Total Posts: 735 |
|
|
| 07 Aug 2017 09:00 PM |
| Do you not understand mouse.Target is an abstract raycast ... that's an extremely expensive script |
|
|
| Report Abuse |
|
|
Casualist
|
  |
| Joined: 26 Jun 2014 |
| Total Posts: 4443 |
|
|
| 07 Aug 2017 09:18 PM |
| Extremely expensive is quite the exaggeration, raycasting is a bit expensive but in the grad scheme of things a drop in the bucket of the physics calculations being performed every heartbeat. This won't change OP's framerate and isn't even close to doing so. If I was doing tens or hundreds of raycasts a call I could see your concern, but it's silly how you're agonizing of a over the cost of a few hundredths of a millisecond to a millisecond. |
|
|
| Report Abuse |
|
|
cabbler
|
  |
| Joined: 19 Jun 2015 |
| Total Posts: 735 |
|
|
| 07 Aug 2017 10:10 PM |
| Obviously not expensive in the context of the entire game; context of this problem. Do you solve all your other issues by doing a massive operation every render frame? but its okay because "ehh its not lagging rn". lol. you don't have to justify your bad script dude. |
|
|
| Report Abuse |
|
|
Casualist
|
  |
| Joined: 26 Jun 2014 |
| Total Posts: 4443 |
|
|
| 07 Aug 2017 10:34 PM |
| It's not a massive operation. It's about ## ###### ## using print. At the end of the day, OP wants something that detects when the target has changed, mouse.move really do ################## ## the target can change regards of whether the mouse moves. Premature and excessive optimization gets in the way of development, and again. We are arguing about hundredths of a millisecond. That's just ridiculous. |
|
|
| Report Abuse |
|
|
Kurokku
|
  |
| Joined: 01 Aug 2015 |
| Total Posts: 3622 |
|
|
| 07 Aug 2017 10:44 PM |
local lastTarget local mouse = game.Players.LocalPlayer:GetMouse()
game:GetService("RunService").Heartbeat:Connect(function() if mouse.Target then if mouse.Target ~= lastTarget then lastTarget = mouse.Target print("Your mouse has found a new target!") end end end)
<script>alert("You wish")</script> |
|
|
| Report Abuse |
|
|
Casualist
|
  |
| Joined: 26 Jun 2014 |
| Total Posts: 4443 |
|
|
| 07 Aug 2017 10:48 PM |
| lmao, why repost a ###### version of my code? If Mouse.Target becomes nil and was not already, that is still a change worth noting, which what you posted fails to acknowledge. |
|
|
| Report Abuse |
|
|
cabbler
|
  |
| Joined: 19 Jun 2015 |
| Total Posts: 735 |
|
|
| 07 Aug 2017 11:00 PM |
| Earlier I had a guy say a single substring is a performance problem. Now hearing that a mouse-camera-based raycast and FindPartOnRay every single frame isn't a problem. Some of you don't understand optimization but that's okay I am posting for the future lurkers who actually do. |
|
|
| Report Abuse |
|
|
Vultorz
|
  |
| Joined: 02 Mar 2015 |
| Total Posts: 2985 |
|
|
| 07 Aug 2017 11:02 PM |
| cabbler, judging by many of your posts, you have no right to correct anyone. |
|
|
| Report Abuse |
|
|
Thane_1
|
  |
| Joined: 08 Apr 2009 |
| Total Posts: 827 |
|
|
| 07 Aug 2017 11:02 PM |
| You don't have to do it every frame, you can do it every 2nd or 3rd frame. |
|
|
| Report Abuse |
|
|
Casualist
|
  |
| Joined: 26 Jun 2014 |
| Total Posts: 4443 |
|
|
| 07 Aug 2017 11:36 PM |
| lmao, cabbler you haven't even suggested a solution, just ragging on what anyone posts, you aren't actually helping anyone. And again, 'optimizing' this would save you a few milliseconds of computation time per second (but that'd be if you actually have an optimal solution to replace it with), and the client would never perceive any difference. |
|
|
| Report Abuse |
|
|