Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript Why is it not working??

Sky_Moonlight

New Coder
Hi I'm a beginner to JavaScript, so can someone please help me. I'm trying to make a game in which the player moves around a circle to catch falling circles. I've been trying to randomize the speed at which each ball falls after touching the bottom of the screen, but for some reason, after the second time, the ball falling doesn't come back to the top after touching the bottom. I'm using p5js to write my code. I've bolded the section I need help with. Thank you! If you need any clarifications, please tell me.


let meteorPosX = 250;
let meteorPosY = 0;
let width = 15;
let height = width;
let wCatcher = 35;
let hCatcher = wCatcher;
let speed = 5;


function setup() {
createCanvas(500, 500);
noStroke();
}

function draw() {
background(0,0,0);

//catcher
fill(245,556,0,)
ellipse(mouseX, mouseY, wCatcher, hCatcher);


//meteor
fill(230,0,0);
ellipse(meteorPosX, meteorPosY, width, height);

distance1 = dist(mouseX, mouseY, meteorPosX, meteorPosY);
distance2 = dist(meteorPosX, meteorPosY, meteorPosX, 500);

if(distance1<15 || distance2==0){
meteorPosY = 0;
meteorPosX=random(0,500);
width = random(10,20);
height = width;
speed = Math.random()*5;
}

meteorPosY = meteorPosY + speed;
}
 
Hello, Welcome to Code Forum!

Glad you decided to joined Code Forum! However, to make the best of your experience here at Code Forum. Could I please have you change your thread title to something more meaningful (e.g. something related to your question). And second, please add all code with our </> BBCode function.
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom