Make image follow designated path?

how can i make an image follow an intricate path. This is for a video game just saying. Currently i am using this code but it only makes it go right for about 200 pixels then back left for 200 and this goes in a loop. How can I make this more intricate?

homelessX is the x position of the image

		if(go == true){
			homelessX += .04f;
			if(homelessX > 800){
				go = false;
			}
		}
		if(go == false){
			homelessX -= .04f;
			if(homelessX < 600){
				go = true;
			}
		}


I don’t know, but I assume you could use a Multiple quadratics and when it gets to the end of the path (curve) jump to the next equation to calculate the new positions.
Basically, break down the path into individual curves, use some tool to find the equation of that curve and use multiple equations to form a single long line, jumping between equations depending on the position.

I’m sure there’s a better way, but that’s my take on the situation.

So do you mean use things like parabola equations?

What is the starting point and what kind of path do you want the sprite to follow? A set path or something dynamic?

Quadratic http://hotmath.com/images/gt/lessons/genericalg1/parabola.gif
Cubic http://math1sfun.files.wordpress.com/2012/07/cubicequ.gif?w=584

EDIT - I’ll make a nice picture with me ‘amazing’ paint skills to show what I mean

where it says Jump, you’d swap the equation.

I want the sprite to follow a intricute path (dynamix is optional) just so the user wouldnt spend enough time figuring out the path, so dynamic if possible

So I would just use these equations and put in the x value of the image as the x value of the equation?

Throw in sprite’s X position or Y position depending on the equation you use and the shape it makes.
and it’ll throw out the opposite value so Y = 2x^2 (which is a curve) at position x = 3 Y will be, 18. x = 4, Y will be 32

Could you show me an example of this code in action? Like if the x value was derpX and the y value was derpY , i am not understanding how you implement the equation in the code

   double Posx = -20;
    double Posy;
    public void random(){
        // render frame
        for(int loop = -20; loop < 20; loop++){
            Posx++;
            // Posy = -0.5x^2
            Posy = -0.5*Math.pow(Posx, 2) + 200;
            System.out.println(Posy);
        }
        
    }

That’s only using one equation, but it gives you the idea, It prints out the values and what it would give in the end is something starting at x = -20 and y = 0 moving to y = 200 at x = 0 then y = 0 at x = 20 in a smooth curve. which you can graph at graph.tk

you completely lost me lol

Posy? cap for a variable name? no!!!

Not trying to be rude but read up on equations a little

http://library.thinkquest.org/20991/prealg/graph.html

Once you get that, you will understand that by plugging in your x value into an equation, it will give you your y value. So as you tick x, your y will change.


int x = 1;
int y = 1;

public void tickObject()
{
      x++;
      y = x + 2;   // This is your equation. It could be something more complicated like Sin(x^2)/arctan(blah blah blah) 
}