How can I reproduce the shooting mechanics from Missile Command from Atari in Godot

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By elmatchobas

Hello guys, I am a brazilian student and I have to reproduce an old school game in godot, but I cant figure it out how to make the shooting mechanics from Missile Command.

The aim moves following the mouse and when a press a buttom the shot have to go up to the mouse location when I pressed and explode.

If someone with more experience in the engine could help me with some idea or a solution I would be very pleased.

:bust_in_silhouette: Reply From: kidscancode

Are you familiar with vector math? If not I highly recommend you read the introduction in the docs.

You have 3 separate parts you need to implement:

  1. Cursor follows mouse
  2. Mouse click launches missile at target
  3. Missile moves to target

Some tips:

  1. Easiest would be to set a custom mouse cursor
  2. Use the _input() function to capture the mouse click event and set a target position using get_global_mouse_position().
  3. Interpolate the position of the missile from the start point to the destination. Alternatively, you could use Line2D to draw the line as in the original game.
:bust_in_silhouette: Reply From: fbrunet99

Sorry too late for your school project, but if someone else searches for this, I created a clone of Missile Command in Godot.

The part that answers your question is mostly in the Missile scene:

The ready() function calculates the direction, then the move_missile() function adds a velocity vector each time the scene is processed until the missile gets to the destination.