Need help on a game again

i have made my game have gravity and every so far has worked great but now when the player is falling because of the gravity the barrier that i already programmed just lets the play fall through, how do i fix this.

Hmmm, so it’s a moving platform that goes up and down? I think if the player is touching the platform, and the platform is moving, the player should move with it too by changing its y value. Type this into the platforms update script:

if(this.hitTest(PLAYER)){
player.y-=PLUG IN NUMBER FOR SPEED!
}


//Or, you could do it this way, which makes the player exactly above the platform:

var numIn = 30
if(this.hitTest(PLAYER)){
if(PLAYER.y<this.y-(((this.height/2)+(PLAYER.height/2))-numIn)){
if(isKeyDown(“JUMPING KEY”)){
}else{
PLAYER.y=this.y-((this.height/2)+(PLAYER.height/2));
}}}


Change the bolded words with what’s needed. The bolded numbers can be adjusted to fit your projects needs!

thank you! =)

1 Like

ok so the code works but right when the ball hits the barrier then the game just stops and i dont have a code set to make the game stop when it hits it.

Is it saying there is an error in your project? Or does the project just stop moving?

If there’s an error, let me know what the error is saying

(if your running the project as an html, it usually freezes when there’s an error)

it stops moving and a screen pops up saying that dont have a scriptable object selelcted

hmmm… can u copy paste the code u used here so I can take a look at it?
(the error can be wrong most of the times)

You don’t have to copy paste the code for everything, only the object with the error

this is code in the barrier/ wall1
var numIn = 30
if(this.hitTest(BALL)){
if(PLAYER.y<this.y-(((this.height/2)+(BALL.height/2))-numIn)){
if(isKeyDown(“up”)){
}else{
BALL.y=this.y-((this.height/2)+(BALL.height/2));
}}}
this is code for ball/player
update:
this.speed_y += 3;
this.x += this.speed_x;
this.y += this.speed_y;
this.speed_x *= 0.9;
if (this.y > 480) {
this.y = 480;
this.speed_y = 0;
}
Default:
this.speed_x = 0;
this.speed_y = 0;
Keydown:
var speed=10;
var speeds=30;
if(key===“up”) {
this.y-=speeds;
}
if(key===“right”) {
this.x+=speed;
}
//wall obstacle
if(this.hitTest(wall1)){
this.x+=20;
}
if(this.hitTest(wall1)){
this.y-=20;
}
if(this.hitTest(wall2)){
this.x+=20;
}
if(this.hitTest(wall2)){
this.y+=20;
}

Line 3, you have PLAYER instead of BALL

omg im so stupid im so sry i didnt see that it works now.

1 Like

it’s ok, ez fix :+1:

Thank you by the way

1 Like

no problem :)

ok now im having the same problem again it just keeps going to the same screen and all i did was remove a couple things i didnt need, and change a number, and its now bringing me to the same screen i dont know why now and i rechecked all the code.

you probably removed something that was being referred to somewhere in your code…
Did the things that u removed have a name?

it had the name wall1 but then i added it back in and it still made the screen pop up i changed the hit test speed for the the ball on the barrier and it now sits on it like i want to but as soon as it hits it, it stops and the screen pops up, and i know i added everything back in exactly how it was because i copied it before i removed it.

hmm… something wrong happened. Try clicking ctrl+z (the shortcut for undoing something) until before you had removed these things, and see if it works.

(if that doesn’t work, let me know what the error is saying)

ok it stopped but now i didnt remove anything and to make the ball stop moving throught the barrier i have to change the speed for, if(this.hitTest( PLAYER )){
player.y-= PLUG IN NUMBER FOR SPEED!
}
where it says plug in speed and i changed it to that speed and its just doing the same thing of having that screen pop up and i havent changed anything else and i went far enough back to where all i had to change to make it not go through the barrier was the speed there.

Ok, do a little quick test. Remove this part of your code, and see if the error happens, or if it stops. If the error doesn’t pop- up, we will know that this was the problem.

ok it stops but the ball is now able to freely pas through the barrier should i try to write another hit test code