0

I feel really stupid asking this. I have a simple 2d platformer. Inside the game I have pipes that I want the player to ride. Basically I have set up a system of PoinfF for each unit it needs to travel. My issue is having smooth travel between them. Can someone write a simple function where I could input point a and point b a then a number between 0 and 1 specifying how along the line it is? Basically I would call the function each frame and set eh cameras position to its output.

I have searched many forms here and I can't find one that works, or I can not understand the math inside. I am sorry to ask this as to you guys it has already been answered.

In summary I am hoping one of you will write me a simple function. It would start with. PointF interpolate (PointF 1, PointF 2, value between 0 and 1)

Btw you do not have to stress over performance this is an amateur game.

Also if there is a good way to make the function accept multiple points that would be great!

CalebK
  • 353
  • 2
  • 11
  • 1
    For a post on StackOverflow, you're going to need to actually ask a specific coding-related question. This site isn't for users to ask for work to be done for them. Your problem seems to have multiple parts. Try breaking it up into concrete pieces. If you're stuck, show what you've tried to far. If you have a math-related question about linear interpolation, check out http://math.stackexchange.com. – Kache Aug 13 '14 at 01:18
  • I think that [lerp](http://en.wikipedia.org/wiki/Lerp_(computing)) is what you want – Liam McInroy Aug 13 '14 at 01:20
  • Yah lerp is what I want. Is their a that has it? – CalebK Aug 13 '14 at 01:34
  • I have tried to get this to work multiple times. Mainly on Saturday Saturday and today I spent over an hour trying to write my own but I couldn't get it to work. I have also tried information from other stack exchange topics but non work. I have invested time into it however I am being hindered by my lack of lerp understanding and that am new to c# – CalebK Aug 13 '14 at 01:39
  • http://stackoverflow.com/questions/12838007/c-sharp-linear-interpolation?rq=1 – Alexei Levenkov Aug 13 '14 at 01:47
  • Wikipedia finally had a function that worked for me thanks outlaw lemur for posting it! – CalebK Aug 13 '14 at 01:51

1 Answers1

5

In kinda-code the function is:

float interpolate(float p1, float p2, float fraction) { return p1 + (p2 - p1) * fraction; }
david.pfx
  • 10,520
  • 3
  • 30
  • 63