[Solved] Getting pinball flippers to push ball

ichimitch

  • Posts: 73
I'm trying to create a basic pinball game framework. I searched for examples or templates to go off but anything I found was for older Stencyl versions and no longer works.

I've attached the game file (.stencyl) for what I have so far. If anyone is willing to take a look under the hood and help me to design behavior for the flippers to push the ball upward, that would be very appreciated. Thanks.

(The reason for no gap between the flippers is for testing.  Once the bahavior is sorted out I'll space them apart)
(Flippers are controlled with Z and X keys)

« Last Edit: April 18, 2018, 10:12:45 pm by ichimitch »

merrak

  • *
  • Posts: 2738
I have a pinball game but it's so old I'd have upgrade it from Stencyl 2.2. If I remember right, though, what I did was apply a turning force when the flipper key was pressed, then a force in the opposite direction when the key was released. Just be sure to set the actor origin to the center of the flipper spindle.

ichimitch

  • Posts: 73
I have a pinball game but it's so old I'd have upgrade it from Stencyl 2.2. If I remember right, though, what I did was apply a turning force when the flipper key was pressed, then a force in the opposite direction when the key was released. Just be sure to set the actor origin to the center of the flipper spindle.

Thanks for the quick reply.

Bare with me, my knowledge of Stencyl is still pretty limited... I've done a course on Udemy by Innes Borkwood and a couple of tutorials by the 'Indie Station' guy on YouTube.  I haven't done much with turning force, yet... but I think I understand.

I've attached the code blocks I've used to attempt using turn force on the flippers. It's not really going to plan :/ The flipper doesn't return to it's starting position properly :S

« Last Edit: April 15, 2018, 10:18:50 pm by ichimitch »

cabinfever

  • Posts: 159
On the released event, move the "set flipper up to 'false' " above the "do after". Just like you have done for the pressed event.
---
How do you handle the event, when user presses the button key, while the flipper is still moving between positions (either up or down)? Do you stop the current movement?
Something like, if actor has turning speed, stop it, and then start the new turning.

ichimitch

  • Posts: 73
I hadn't accounted for checking if the flipper was moving. Thanks, that idea helped a lot.

I've attached a screenshot with the new code and a stencyl file for curious onlookers. 

Given that I'm a noob there's probably a much better way to handle this.. So if anyone comes up with a better behavior, please do share.

On the released event, move the "set flipper up to 'false' " above the "do after". Just like you have done for the pressed event.
---
How do you handle the event, when user presses the button key, while the flipper is still moving between positions (either up or down)? Do you stop the current movement?
Something like, if actor has turning speed, stop it, and then start the new turning.

JeffreyDriver

  • Posts: 2262
I made a game with pinball flippers, it uses the joints extension, but can probably be tweaked to work without.

ichimitch

  • Posts: 73
Thanks. Off doing my crappy day job but as soon as I'm home I'll check it out

cabinfever

  • Posts: 159
NEVER use timed-loops inside 'when updating' method.
(you just end up in big mess, since that 'when updating' is done 100 times a second and chance of getting multiple delayed actions (uncontrolled code branching) is highly likely)

Better use custom triggered events in general.

For key-press/releases, just use them in their own events. Which then trigger custom events.
( Like: move paddle up, stop padlle, get paddle current speed, move paddle down )

merrak

  • *
  • Posts: 2738
Joints sounds like a better way to go. The pinball game I made was my second stencyl game ever, and was also on a much older  version. I'd look into doing it differently if I was remaking it.

ichimitch

  • Posts: 73
Thanks, Cabinfever.

I've noted that timed-loops in update events is bad practice. I'll avoid it in future.

Is this what you meant I should do?

Better use custom triggered events in general.

For key-press/releases, just use them in their own events. Which then trigger custom events.
( Like: move paddle up, stop padlle, get paddle current speed, move paddle down )

ichimitch

  • Posts: 73
I made a game with pinball flippers, it uses the joints extension, but can probably be tweaked to work without.

I downloaded the joints extension, installed it and enabled it on the pinball game. Then I copied your code verbatim but for some reason it didn't work... :/   I ended up doing as you suggested and tweaked it to work without the joints extension. Thanks very much for your solution.

Also thanks everyone else for your comments. I'm happy with the current solution so I can finally move on from the damn flipper code and start on the rest of the game. Cheers.