Make a catapult throw to a chosen distance, with the stone leaving from the tip of the arm
A catapult in a strategy game is usually a stone that appears from nowhere while the arm does its own thing. If the arm and the stone follow the same physics, the arm swing tells the player how far it will throw. This entry joins them: speed of the tip, release angle and the place where the stone is born, worked out from the distance wanted.
Why this works
A stone flies the way it was moving at the instant it let go. So the arm's turning speed and the angle of release together decide the flight, and the stone must start at the arm's tip. Working backwards from the wanted distance makes the picture and the landing agree.
When not to use it
Overkill for arcade games where a stone just flies along a nice curve to the target. If nobody sees the arm or the exact landing matters little, draw a simple arc and skip the physics.
In the full entry
- What to build, step by step
- Starting values and the reason for each
- 3 common mistakes and the fix
- A diagram of every state
- 54 lines of example code with 4 checks that pass
- How your AI shows you that it works
Say this to your AI
Use the Spielerando entry "Make a catapult throw to a chosen distance, with the stone leaving from the tip of the arm" (read_entry catapult-throws-to-a-chosen-distance-from-the-arm-tip) in my game. Build it step by step, and show me how you checked that it works.Or skip this and connect the MCP: your AI then finds all of this by itself.Connect the MCP