Hello, I created simple shooting system on Gdscript in 2D platformer. If my character look right = he will shoot right, if he looks left = he shoots left, but i want to improve my system and decided to do something like (Character hands follow mouse and shoots at mouse position),but I don't even know how to start. Any help? (Sorry if there are errors in the text, I'm still learning English)

From my experience, there are several ways to do this. The most simple way is to have your character's hands/arms a separate sprite and then rotate them to look at the mouse. Then you can spawn bullets/arrows/whatever from a child node of the character's hands/arms, and then move the projectile according to the direction it is facing.

While the code is for Godot 2.0, I would take a look at the LookAt.gd file from the Godot 2.0 GitHub demo repository, as it shows a few different ways to rotate a sprite to look at the mouse. You may need to convert a few things if you are using Godot 3.0, but it shouldn't be too hard to do. Let me know if you have any issues and I'll see what I can do!

Here is a Godot QA answer that has a example project that appears to aim at the mouse. I have no idea which version of Godot it is for, though looking at the posting date it is probably Godot 2.0 as well.

There is also a quick, slightly over 1 minute Youtube video showing how to make a Cannon head aim at the mouse with Godot 3.0.

For moving the node in the direction it is facing, I posted some example code in this topic awhile ago. I think the code should still work.

Hopefully this helps! :smile:

@TwistedTwigleg said: From my experience, there are several ways to do this. The most simple way is to have your character's hands/arms a separate sprite and then rotate them to look at the mouse. Then you can spawn bullets/arrows/whatever from a child node of the character's hands/arms, and then move the projectile according to the direction it is facing.

While the code is for Godot 2.0, I would take a look at the LookAt.gd file from the Godot 2.0 GitHub demo repository, as it shows a few different ways to rotate a sprite to look at the mouse. You may need to convert a few things if you are using Godot 3.0, but it shouldn't be too hard to do. Let me know if you have any issues and I'll see what I can do!

Here is a Godot QA answer that has a example project that appears to aim at the mouse. I have no idea which version of Godot it is for, though looking at the posting date it is probably Godot 2.0 as well.

There is also a quick, slightly over 1 minute Youtube video showing how to make a Cannon head aim at the mouse with Godot 3.0.

For moving the node in the direction it is facing, I posted some example code in this topic awhile ago. I think the code should still work.

Hopefully this helps! :smile:

Thanks for answer

4 years later