Collision of the player with the moving rectangles

https://editor.p5js.org/Nis_Collect/sketches/U0p3GjOK1

Given above is the link of my project. Someone please help me by reviewing my code and telling me that how can I confirm the collision of the player with the moving rectangles.
Please provide me the code of only the lines which specifies the collision of the player and the moving blocks.
I tried so many ways but I can’t figure it out.
Please please help me.

Is that link to the right code, because I cannot see anything about collisions or even red rectangles?

Yeah it’s correct link. But I am sorry that the moving rectangles have white colour.
And ofcourse there cannot be any line of code of collision because that’s what I am asking

I see. So you want to check if two rectangles or objects have collided? It called collision detection. I don’t know how accurate you want to be, but possibly easiest way is to check distance of the objects and when it’s small enough collision has happened. Distance depends on size, shape and accuracy you’re looking for.

You get distance with dist()-function. I would use center points of the objects to get distances. Naturally you need to take that to account when you draw those objects, so that you set them in place with the same center point.

1 Like

Ya you are right but I already have tried it. And unfortunately it doesn’t work there .
Can, you please try this in my code and if you get that right, please send me the link of that code

Please sir, please , try…

There are plenty of examples out there for you that you can learn from.

Here is one that you may glean some insight from:

:)

Can you please apply it in my code and check whether it is working or not?
If it works, then send me the link of the code please

No, I won’t. Idea of processing is to learn. What would you learn if I wrote the code for you? I’m happy to help you find the solution. This is a free time activity for me so it shouldn’t feel like work.

1 Like

The rest is up to you.
I will not be assisting you any further.

I am not telling this to you because of my laziness but I am telling this to you because I have already tried it, even then it shows an eroor- dist() was expecting 4 arguments but received only 0 arguments.
I think I am not writing the dist() function at a correct place and with correctly passed parameters. That’s why I am humbly requesting to please write that function in the proper place and with correctly passed parameters/arguments.
Please please please tell Sir,please…please… Sir… please

Sir, please try to understand. I am telling the same to you also. I am not telling this to you because of my laziness but I am telling this to you because I have already tried it, even then it shows an eroor- dist() was expecting 4 arguments but received on 0 arguments.
I think I am not writing the dist() function at a correct place and with correctly passed parameters. That’s why I am humbly requesting to please write that function in the proper place and with correctly passed parameters/arguments.
Please please please tell Sir,please…please… Sir… please

It isn’t a free time service for me. I have been challenged and also I have a bet to develop a game in p5.js. And also, if I would be able to do so, I will get selected in my school’s CodingTeam.

Have you looked at the documentation of dist()-function? dist() / Reference / Processing.org

You need to give it x and y coordinates of two points (center points of rectangles for instance) and it will return distance between those points.

So please sir try to understand me

Sir sir, even then it gives the same error

Did you give it four parameters? it should be something like dist(x1,y1,x2,y2) where x1 and y1 are coordinates of the first point and x2 and y2 are coordinates of the second point

Holy shit, @Nis

We all understand you. It sucks to not know where to start and what is wrong. Do the following thing:

1)Write a line of code that you think should give you the distance between the two rectangles. Even if it is wrong.

  1. Post it here along with a description of what you think it should do, what it actually does and what you tried to fix it.

  2. Help will arrive :slight_smile:

The topic continues here:

:)