I started working on a breakout style game, with the bat controlled by the mouse. The game is supposed to start with the ball on top of the bat, centered, so the player can choose from which position to let it go. I set the bat to follow the mouse's horizontal position and had it bound to the layout. To make the ball always stay in the same position relative to the bat, I made it follow the bat's horizontal position. My events look like this:
Yet, if you actually playtest the game, you'll see that the ball seems to be following the mouse instead of the bat. if you make the bat reach the end of the layout and stop due to being bound, the ball continues moving.
What did I do wrong here? How can I make the ball behave as I want it to?
I think it's because the position of the bat is set to the mouse.X
then the position of the ball is set to the bat.X
then the "bound to layout" behavior set back the bat.x to the right position.
you should use the pin behavior and pin the ball to the bat instead of manualy setting it's position
Try reversing the order of the two events.
Using the pin behavior worked. Thanks.
I'm still not quite sure why it wasn't working before, though. Is it because the "bound to layout" behavior still lets the object go outside, but snaps it to the right position immediately after?
Develop games in your browser. Powerful, performant & highly capable.
Yes i think it's because of that. The behavior is executed after your event.
So if you move the cursors to -10 (outside the layout)
in the same tick