Tank that aims with the mouse
Advanced · Use the Vehicles and Combat extension: the sprite smoothly turns to the mouse and drives with the arrows.
Interactive tutorial: the editor checks each step by itself.
- Add the "Vehicles and Combat" extension.
- Choose a sprite and drag "when green flag clicked" with a "forever" below.
- Inside the "forever", put "smoothly turn toward mouse pointer".
- Click the flag and move the mouse around the stage: the sprite turns slowly until it aims.
- Put in the "forever" an "if key up arrow pressed?" with "drive: move 3 steps and turn 0 degrees" inside.
- Open Costumes > Edit in painter > "Image points" tool (P key) and create a point named "tip" at the front of the sprite.
- Create a "Bullet" sprite and, on the main sprite, use "create clone of Bullet at my point tip pointing my direction" when space is pressed.
- Challenge: open the "Tank battle" example (Examples) and see the turret ATTACHED to the chassis with "attach my position to point…". (challenge)