Hi everyone, I have an idea to code a situation like this: A spaceship in space fires a missile, but it doesn't fly straight to the enemy, when it is just fired from the spaceship's cannon, the missile will fly in an arc before reaching the enemy. (in game 2D pixel, not 3D).
I look forward to receiving guidance from everyone, thank you very much.

    Odin Is the target static or moving?

    • Odin replied to this.

      xyz maybe both, my Master. Because it can attack building and other ships. So, I think both. May you code an example for me,my Master! Thank you so much for helping.

      • xyz replied to this.

        Odin May you code an example for me

        I don't think so 🙂
        A good way to approach it would be to implement a simple homing missile. Launch the projectile not aiming directly at the target. At each frame rotate the projectile tiny bit towards the target. It will eventually find its way to the target and the trajectory will be curved.

        Odin for an arc, use a sin() function
        sin(a)
        this draws a curve that goes up and down. by scaling a you can match the start and end of the curve to the position of the target.

        another way is to just set a target position or reference an enemy, and rotate towards the target with the look_at() function. for more complex behaviour you would need to calculate global_positions and vectors with looking_at(). this code would be in the missile.
        you can launch the missile to the side to start the curve, and set rotation speed to something small.

        look_at rotates the missile immediately towards the target.
        looking_at returns the rotation needed and can be slerped to make it rotate slower.

        #in 3D
        const rotation_speed = 0.2

        quaternion = quaternion.slerp(global_transform.looking_at(target.global_position - global_position).basis.get_rotation_quaternion(), rotation_speed)

        another way is with a tween.

        • Odin replied to this.

          Since it's 2d, maybe draw a picture of what you had in mind for the ship and the targets. With 2d, I think you would have to scale it smaller as it got further away and rotating maybe with an animation like turning left or turning right, just moving it one frame depending on the distance to the target. The only way a missile would arc is if it was a homing missile. You wouldn't see it move with gravity like a cannon ball or something.

          Jesusemora sorry for the bother, can you code me an example of this case? In 2D, 1 ship shoots out 1 arc missile to 1 enemy ship. I sincerely thank you very much.

          Search "godot 2d homing missile" on youtube