p5 Collision Detection (again) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

p5 Collision Detection (again)

I don't know why this isn't working. The x axis is getting added to 2 each millisecond. If it the value is higher than the total width, it adds -2 therefore going backwards. So I don't know why this isn't working. It has worked before but not now https://code.sololearn.com/WQVhKKBeno2I/?ref=app

7th Jun 2019, 6:08 PM
Clueless Coder
Clueless Coder - avatar
7 Answers
+ 1
https://code.sololearn.com/WaKjtkPV2Ee5 I changed some codes and added other way for handling gravity and jump.
8th Jun 2019, 1:53 PM
Farry
Farry - avatar
+ 3
Farry I thought ODLNT would be better at helping with this, but because he hasn't responded yet, maybe you can help make the jump animation smooth (sorry for wasting your time again)
8th Jun 2019, 12:22 PM
Clueless Coder
Clueless Coder - avatar
+ 3
You're a legend, thanks!
8th Jun 2019, 2:42 PM
Clueless Coder
Clueless Coder - avatar
+ 2
Do you know why this collision isn't working? It has worked in previous codes but not now. I am finding the dist between the 2 balls, if it is less than the 2 radii added together they should collide. I don't know why this isn't working
8th Jun 2019, 7:31 AM
Clueless Coder
Clueless Coder - avatar
+ 1
you are recreating the xSpeed var every time you call the move method. you have to store it as a property of the object and multiply it by -1 whenever is touches the walls. // add this in conatructor this.xSpeed=2; // update the move method move(){ this.x += this.xSpeed; if(this.x > width || this.x < 0){ this.xSpeed*=-1; console.log("hit"); } }
7th Jun 2019, 6:29 PM
Farry
Farry - avatar
+ 1
the problem is that you are not updating the distance 'd' property every time you move the object. update this.d in the move method and it should work fine
8th Jun 2019, 9:10 AM
Farry
Farry - avatar
+ 1
np
8th Jun 2019, 2:43 PM
Farry
Farry - avatar