Does anyone know how to make it so thing can exist. Like if my character is about to touch a wall how would you make it so they can’t walk through it. Maybe code… or put them on the same layer. Just someone please help…
hi @ANTHONY_VEGA-CARDONA
There is a bit of code that you run in the update() section, so it runs constantly every cycle…
if(this.hitTest(wall1) ) {
// flag to see I have hit the wall already to avoid the object going mad vibrating back and forth
if (!this.hitWall) {
// movement of my object is reversed away from the wall
this.xMove = this.xMove * -1;
// set flag true. I then wait a short while
this.hitWall = true;
}
}
I have 4 lines called wall1, wall2, wall3, wall4 that is around my page in a box.
if an object (this), touches a wall, say wall1 the above code in the update() function is true so you know you have hit the wall. You can see what I do is then reverse direction. I do this same test for wall2,wall3,wall4
look at my asteroids game for the code…
asteroids demo-6-15-2020_6-35-32PM.wick (1.8 MB)
I hope this helps. Let me know if I can explain further. Thanks to @Hamzah_Alani who gave me this first.