Make object run up ramps

So, I am trying to make a 2D game where there is a ball going on forever and there is a black line dividing the screen in two halfs (upper half and lower half). There are also some objects that the ball must dodge. the only thing the User does is Click that make the ball change the half that it is located. I would like though to add ramps that the ball can run on so it gets more interesting. any ideas ?

1 Like

Here we see a picture that is helpful.

Normally the ball (green) is moving along the ground (black).

That means its center (purple) follows a straight path (yellow).

But when it gets close to a ramp (red), it needs to stop following the straight path at some point (pink), and instead follow a path over the ramp (orange).

Once it gets over the ramp, it falls back down and lands on the ground again, at which point (blue) it starts following the straight path again.

Be cause the red ramp has a fixed width, you can determine (based on its location) the points at which the ball needs to have its path adjusted due to the ramp.

… This is, of course, assuming your ball has no momentum / you’re not using a physics model to move your ball. If it does, why, then simply apply a force upward along the normal of the ramp when the ball is touching it.

… Helping you more is hard without seeing some example code of a ball.

1 Like

Well I see the idea… (Hello again btw) The only thing is that if I try o implement this I have to change the whole code which is not that hard as it isn’t big. Though based on the following code, what do you suggest. (on thing is that the ball is not following a certain path and there is no gravity yet as it wouldn’t climb anywhere)

Obstacles class:

class Obstacles{
  PVector pos = new PVector();
  PVector dim = new PVector();

  Obstacles(float x, float h, float w){
  void drawRect(){
  boolean rectHit(){
    if(ball.pos.x+size/2>pos.x && ball.pos.x-size/2<dim.x+pos.x && ball.pos.y==side*size/2){
      return true;
    return false;

  float sideInit(){
   side = random(0,1);
   if(side>0.5){return 1;}
   return -1;

ball class (Runner):

class Runner{
  PVector pos = new PVector();
  Runner(float x,float y){
  void show(){
   //b = loadImage("ball.png");
  void invert(){

Main program:

Runner ball;
//PImage b;
Obstacles obj = new Obstacles(0,0,0);
int size=50;
float offx=0;
float side;

void setup(){
 ball = new Runner(size/2+width/6.4,size/2);
 side = obj.sideInit();
 obj = new Obstacles(width,side*random(50,90),random(size/2,100));

void draw(){
 if (obj.rectHit()){noLoop();}
 if (obj.pos.x<offx){side=obj.sideInit();obj = new Obstacles(width+offx,side*random(50,90),random(size/2,100));}

void mousePressed(){

void  keyPressed(){

Thanks in advance :slight_smile:

1 Like

So will the gravity be arcade gravity, or more like physics simulation gravity? What is the control scheme like – left right arrows, hitting, rubber band dragging? Will there jumping?

Between creating or using a full physics sim on the one hand (complex) and having a piecewise height collision function on the other (simple), the question is how abstract and simple your solution should be.

Well I will use arcade gravity, like y-- until hit ground or sth. The controls are pretty simple. Click to change the side you are. (explained in description) So the ball will run into a ramp. no jumping no nothing. just continuous movement forward.