Hi! I’m very new to Godot, with a little bit of coding experience. I’m making a sample game to try out the engine. In the current version of the game, I have a player that can move (not much, I know…) and a weapon that does nothing right now. What I want is for the weapon to be a set distance from the player in the mouse cursor’s direction. Currently, I can get the weapon to point towards the mouse cursor but there is no “Move __ pixels in the direction you’re looking in” command that I can enter into the code.
An easy way of doing that is to add a node for the weapon that’s a child node of the player. That way, you could rotate the weapon independently from the player.
Once that works, you can add a third node in between to act as the rotation pivot of the weapon, that will allow you to place the weapon at any distance, since the rotated object will be its parent.
So the nodes setup will look something like this:
Player
|_ WeaponRotation
|_ Weapon
Another way of doing that is to calculate everything in code, which is not that hard, but I like the nodes solution better as it’s perfect to modify the weapon distance visually.
That’s the technique I’m using for my current project and it works like a charm.
Let me know if that helps or if you need a more detailed explanation.
I like the idea but I don’t think I was clear enough in my description. Part of my idea for the weapon is that it launches forward when used, and has a hitbox. The main part being that it launches forward. Does having it as a child node prevent that?
By changing the WeaponPivot node rotation, you can change the aim (as explained previously but I’ll still add a gif for the sake of giving a full breakdown of my idea):
By changing the Weapon local x position, you adjust the distance:
And the cool thing is, you don’t have to do anything else for both the rotation and the weapon forward launching to work:
You can then work on a code that will do the launch motion the way you want, you can also do a back and forth motion, etc.
I hope I’ve understood your problem, feel free to tell me if that still doesn’t work for what you’re trying to do.