Author Topic: SpringPanel - Threshold value, why not constant?  (Read 1690 times)

helmesjo

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 116
    • View Profile
SpringPanel - Threshold value, why not constant?
« on: April 07, 2014, 05:20:51 AM »
Hi!

Just a quick question - What's the logic behind dynamically calculating the threshold depending on the distance form current position to the target position (when started)? Why isn't the threshold a constant, say 1px? Don't see why anyone would want a threshold of much larger than 1px.

Reason I ask is because with the current solution, the SpringPanel will snap into target-position to soon if the distance is large between the two when the SpringPanel is begun, since the threshold might be >10px. This makes it look laggy.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: SpringPanel - Threshold value, why not constant?
« Reply #1 on: April 07, 2014, 09:59:17 PM »
Good question. No reason I can discern. Try changing the statement to be just
  1.                 if ((after - target).sqrMagnitude < 0.01f)
  2.                 {
  3.                         after = target;
  4.                         enabled = false;
  5.                         trigger = true;
  6.                 }

helmesjo

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 116
    • View Profile
Re: SpringPanel - Threshold value, why not constant?
« Reply #2 on: April 07, 2014, 11:58:35 PM »
That's what I ended up doing :)

Thanks!