+ 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
7 Answers
+ 1
https://code.sololearn.com/WaKjtkPV2Ee5
I changed some codes and added other way for handling gravity and jump.
+ 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)
+ 3
You're a legend, thanks!
+ 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
+ 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");
}
}
+ 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
+ 1
np