Author Topic: Camera accelerate and decelerate with scroll  (Read 977 times)

Offline kkl

  • float
  • ****
  • Posts: 291
    • View Profile
Camera accelerate and decelerate with scroll
« on: December 15, 2014, 02:29:40 am »
Hi,

Has anyone tried camera smooth scrolling before? Something like, the camera accelerates based on velocity and slows down(decelerate) when the touch event stops.
« Last Edit: December 15, 2014, 02:33:59 am by kkl »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Camera accelerate and decelerate with scroll
« Reply #1 on: December 15, 2014, 07:53:17 am »
Should be simple to do. Or do you have any issues with it?

Offline kkl

  • float
  • ****
  • Posts: 291
    • View Profile
Re: Camera accelerate and decelerate with scroll
« Reply #2 on: December 15, 2014, 08:59:49 am »
It's easy if the camera moves according to the distance of the scroll, but it would look artificial and the scrolling is not smooth. I kinda stuck at scrolling acceleration and deceleration parts. Does it involve with velocity?
« Last Edit: December 15, 2014, 09:12:14 am by kkl »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Camera accelerate and decelerate with scroll
« Reply #3 on: December 15, 2014, 02:36:08 pm »
Have you tried some simple (linear) damping?

Offline kkl

  • float
  • ****
  • Posts: 291
    • View Profile
Re: Camera accelerate and decelerate with scroll
« Reply #4 on: December 16, 2014, 02:31:06 am »
I've never tried physics stuff before. Do you know any good library or tutorial that might helps?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Camera accelerate and decelerate with scroll
« Reply #5 on: December 16, 2014, 07:47:11 am »
I don't think that this needs a library. If you have a target speed for each frame, just try something like

Code: [Select]
camSpeed=(5*oldSpeed+targetSpeed)/6;
oldSpeed=camSpeed;

Then again, i'm still not entirely sure what you actually want to implement, so my suggestions might be totally missing the point... ;)

Offline kkl

  • float
  • ****
  • Posts: 291
    • View Profile
Re: Camera accelerate and decelerate with scroll
« Reply #6 on: December 17, 2014, 08:43:09 am »
Tat works like magic! Exactly wat i've been looking for.. but i still hav problem if the camera moves to the edge(i set a position limitation to left and right) and the scroll just stop right away instead of smooth scroll to edge. Do you have any idea to fix tat?