Homing Rocket in 2 lines [Game Maker | Basics]
This basics video tutorial shows you how homing can work in GameMaker Studio with 2 lines of code. There will be a follow up video on a homing rocket barrage like you see in games like Armored Core, but the cheap man's 2D version.
I got the inspiration from Ellaris who is a discord member, so thanks for the idea buddy! The 2 lines are very easy to do and work more or less but are a building block to advance this concept.
First we need to create the rocket and give it an inital speed, direction and angle to start of with and gradually change the flying direction.
So what are those 2 lines? Well, we add constantly in the step event of each rocket to it a value that gradually ("delayed") turns towards it's target position. For that we need the current direction of the rocket and the perfect direction from the rocket to the target (which we get by the rocket's x,y and the targets x,y and get it by point direction). Then we get the resulting angle difference and use sign to clamp the result to 0,1,-1. That added to the current direction turns the rocket towards the the target, but we can use a fixed value to increase/decrease the turning around speed to our liking. Then we set the new direction to the image angle so that visuall it looks sound aswell. That's it!
The code if found as usual in the comment section.
🚧 For the future: There will be follow up video that shows how to visually advance this core setup to an homing missile barrage
👑 Support me and get fresh game art and game maker projects every month:
https://www.patreon.com/1upindie
Follow me on:
📸 Instangram: https://www.instagram.com/1upindie
🐦 Twitter: https://twitter.com/1upIndie
💬 Discord: https://discord.gg/gvr98nb
📜 Udemy: https://www.udemy.com/course/become-a-video-game-developer-with-gms-23/ (See youtube about page for discount)
CHAPTERS
-------------------------------------------------------------------------------------------------------
0:00 What we will do
0:59 Specific hit animation (elemental, weapon etc.)
1:11 The 2 lines that steer the rocket
2:28 When the rocket hits an enemy
2:45 Player setup, input and spawning a rocket
5:13 What the 2 lines mean in detail