0 Favourites

Following an object set to follow the mouse

  • 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?

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • 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

    • The bat X is set to -10
    • The ball X is set to the bat X (so -10)
    • The behavior is executed and set the bat X to 0 to get it inside the layout but it's to late for the ball, it is set to -10 and will stay here
    • The screen is rendered and you see the ball at -10 and the bat at 0
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
167 14,517
DMT2005's avatar
DMT2005
Unread hot topic
96 57,363
bitworks's avatar
bitworks
Unread hot topic
90 77,104
leonhard's avatar
leonhard