freezy / VisualPinball.Engine

:video_game: Visual Pinball Engine for Unity
https://docs.visualpinball.org
GNU General Public License v3.0
406 stars 62 forks source link

Add mech support for PinMAME #339

Closed freezy closed 2 years ago

freezy commented 2 years ago

PinMAME offers mech simulation, i.e. it can drive a motor for you and toggle switches if necessary. Most of the time I've spent on this PR went actually into figuring out how it works exactly and documenting it.

The general idea is to make it easy for creators to use PinMAME's mech sim if desired, but be able to easily swap it out by a custom component if necessary. We'll provide such components at some point, right now the only one is called StepRotatorMechComponent and just does linear movement for a defined length.

If you actually want to use this (our use case is the T2 cannon), you would use three components:

  1. The PinMAME mech component that tells PinMAME to simulate the mech and outputs speed and position
  2. A "cannon rotator" component that takes in that speed and position and converts it into an angle
  3. And a "rotator" component that takes in the angle and applies it to the playfield geometry (and balls, if necessary).

Each component could be swapped by another one, giving you "bricks" to adapt to your game logic. It's currently pretty basic, but it's a good foundation for more complex setups. In the future we could support node graphs where you could basically do whatever you need to compute, graphically.

By the way I did plot how the cannon of T2 moves. Looks like a sine function, which we could reproduce quite easily, but that's for another PR.

image

Finally, here the T2 gun, simulated by PinMAME, in action:

https://user-images.githubusercontent.com/70426/140429006-9aaa1c92-5d71-4455-ae51-14818eb08f86.mp4

This PR also requires VisualPinball/VisualPinball.Engine.PinMAME#15, where the actual component is implemented.

codecov[bot] commented 2 years ago

Codecov Report

Merging #339 (fd587fa) into master (f2e1a8c) will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #339   +/-   ##
=======================================
  Coverage   83.90%   83.90%           
=======================================
  Files         125      125           
  Lines        6734     6734           
=======================================
  Hits         5650     5650           
  Misses       1084     1084           

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update f6cc3fe...fd587fa. Read the comment docs.