Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

998192 Posts in 39146 Topics- by 30558 Members - Latest Member: Ilya Salamatov

April 18, 2014, 03:29:13 AM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)Camera Arriving at Destination
Pages: [1]
Print
Author Topic: Camera Arriving at Destination  (Read 335 times)
James Daniello
Level 2
**


2nd Place TIGSource Member of the Year


View Profile WWW Email
« on: May 07, 2013, 08:39:06 AM »

Hey guys. I'm stumped here trying to get my object to slow as it reaches its target. It's actually the camera. I'd like to set its target X & Y, and the number of frames it should take to move across the map and it reaches it's target the camera slows.

So, given it's position, it's distance from target, and the number of steps it should take, I can't seem to figure out an equation that will suffice.  If anyone can help here, that would be tremendous.

The goal being that wherever the camera is, I can tell it pan across the map in "t" (e.g. "t" = 60 frames), and it will start moving, and as it gets closer, it moves less, finally stopping at the target as "t" == 0. This way, the number of frames can be adjusted and it will move slower or faster, but it will always slow as it gets there.

Any ideas?

(Bonus points for any other camera motion you guys can help with).
Logged

Gregg Williams
Level 10
*****


Retromite code daemon


View Profile WWW Email
« Reply #1 on: May 07, 2013, 09:06:48 AM »

Look up motion tweening, a basic linear tween with an appropriate easing function would handle that easily.
Logged

ThemsAllTook
Moderator
Level 10
******


Alex Diener


View Profile WWW
« Reply #2 on: May 07, 2013, 09:06:58 AM »

Linear interpolation weighted by sin()?

(I can elaborate if that doesn't make sense)
Logged
James Daniello
Level 2
**


2nd Place TIGSource Member of the Year


View Profile WWW Email
« Reply #3 on: May 07, 2013, 09:45:21 AM »

I'll look up tweening when I get off work. That should help. A definite problem I had was trying to explain my problem to google. Thanks.

Also, I'm definitely down to hear more about linear interpolation. It's been a bit of time since I've had to do any math harder than trig, algebra, or geometry though, so you might have to break it down a bit.
Logged

ThemsAllTook
Moderator
Level 10
******


Alex Diener


View Profile WWW
« Reply #4 on: May 07, 2013, 10:34:42 AM »

Sure. Here's a basic ease out interpolation using sin (pseudocode, written off the top of my head and untested):

Code:
// t is assumed to be between 0 and 1; 0 returns initial, 1 returns target, values in between are weighted more heavily toward target than initial
vector2 sinInterpolate(vector2 initial, vector2 target, float t) {
  float weightedT = sin(M_PI * 0.5 * t);
  // This assumes operator overloading for vector2; break it down to x/y if necessary
  return initial + (target - initial) * weightedT;
}
Logged
James Daniello
Level 2
**


2nd Place TIGSource Member of the Year


View Profile WWW Email
« Reply #5 on: May 07, 2013, 06:38:12 PM »

Thanks, ThemsAllTook! That worked like a charm.  Hand Thumbs Up Right
Logged

nikki
Level 10
*****


View Profile Email
« Reply #6 on: May 08, 2013, 04:55:45 AM »

yeah tweening and easing are what you want.

have a look/play with the interactive demo on http://www.greensock.com/get-started-tweening/
oh and maybe it's helpful to think in units of seconds instead of frames.
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic