A mounted gun snaps around when a second player takes over, or turns the long way round
Turrets and ship cannons that two friends take turns on have a nasty moment: the new gunner looks somewhere else, and the gun jumps to it. Or it spins nearly all the way round because the aim lies just behind the mounting. Here is how a gun swivels sensibly and survives a change of hands.
Why this works
The gun is a thing with its own heading, and a gunner only asks it to turn. Because the heading never gets copied from a person, a change of hands cannot make it jump, and measuring angles from the mount gives the shorter turn inside the allowed arc.
When not to use it
Wrong for a weapon that should follow the player's view exactly, such as a handheld gun or a sniper scope, where any lag feels like bad controls. It also does not suit a fixed-aim gun with no swivel at all.
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
- 22 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 "A mounted gun snaps around when a second player takes over, or turns the long way round" (read_entry shared-turret-keeps-its-aim-when-the-gunner-changes) 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