Things on the same layer interact better

I’ll try to make this post as short as possible, so here’s a simple gif:


Wick Editor 1.18 (3)


explaining gif

Ok, so this is a new game that I started working on, where the object moves with a mouse, which makes it even harder to make perfect walls… but I noticed that the walls work better when they’re on the same layer as the green circle… but the path that follows the green circle goes where the circle is supposed to be if it hit the wall… yet the green circle refuses to have the wall stop it from keeping up with the mouse. That’s why things on the same layer interact better with each other.

gif is a loop, don't get tricked

Somehow I made the gif a perfect loop without noticing, so don’t get tricked by it, & u can watch the timeline to know if the gif restarted or not ( gif= 31 seconds)


#bug-reporting

1 Like

First of all, nice concept there. : )

I think you have a race condition problem. Since I’m not seeing your code, I’m only guessing. If you have code in different layers, just keep in mind that they execute in order from top to bottom. Lets say that your app has 2 layers. Lets say at the top layer you have the code for the ball to stops with the wall. Then in the second/bottom layer you have the code that tells the ball to follow the mouse. In this example, the second layer code will override the first layer code. As a result you will see the ball trespassing the wall. If that is the case, for multiple layers you should have the code for the walls executing after the code for the ball to follow the mouse.

Your info seems correct : )

The reason the project gave me different results when I changed the layers position is because I was defining obj1’s X value from two different scripts, so it’s kind of interesting to see which one the project chooses to run, and which one it will ignore. It was like u said, the project ran the top layer script first, then it focused more on the bottom layers, and knowing what layer is more accurate or which one runs first is really important when it comes to coding.


4 anyone interested

Make an object that follows the mouse and name it obj1. Then make another object, and add this to it’s code: “if(this.hitTest(obj1)){obj1.x=this.x;};”

After you do that, send objects to front or to back, or to top or bottom layer, to see a difference.

:speech_balloon:

We always had have the chrome js console, but now we will have a built-in console. That is great to debug problems like these. You could do console.log("Executing from here..."); and console.log("Executing from there..."); and so on… In that way you would be able to see the execution order and be more efficient with the debugging process.

I’m looking forward to see your working prototype soon…

1 Like