Following an object set to follow the mouse

Get help using Construct 2

Post » Thu Sep 24, 2015 9:37 am

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:

Image

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?
B
15
S
2
G
3
Posts: 45
Reputation: 2,638

Post » Thu Sep 24, 2015 10:12 am

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
B
13
S
4
G
4
Posts: 74
Reputation: 3,509

Post » Thu Sep 24, 2015 10:56 am

Try reversing the order of the two events.
Lokkim Games: Constructor Dude - Fun platformer game, PuzCro - Difficult puzzle game demo
B
9
S
3
G
1
Posts: 38
Reputation: 795

Post » Thu Sep 24, 2015 1:30 pm

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?
B
15
S
2
G
3
Posts: 45
Reputation: 2,638

Post » Thu Sep 24, 2015 1:44 pm

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
B
13
S
4
G
4
Posts: 74
Reputation: 3,509


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 10 guests