0 votes

Hey! I'm building a Twin Stick shooter prototype for fun and learning.

Analog stick based movement with the left stick on my controller is working fine.

I've also got a little arrow sprite that is visible when the right stick is pressed, to show which direction you're aiming. I've got this rotating in the direction the right stick is pointing just fine too.

The code for this looks like this:

if is_aiming(): #True if right stick is pressed in any direction. arrow.visible = true arrow.rotation = aim_direction.angle() #aim_direction is a normalized Vector2 else: arrow.visible = false

Now what I want to do next is get the arrow to offset itself from the player sprite by a standard distance in that same aim_direction. But I can't figure out how to do that.

Say I want the arrow sprite to display 16 pixels away from the player sprite in whatever direction the right stick is being held. How do I go about doing this? Can anyone point me in the right direction?

in Engine by (22 points)

2 Answers

+1 vote
Best answer

If the arrow is placed as child of the character, you could try something like

arrow.position = 16*aim_direction

Assuming aim_direction is normalized.

I'm assuming the arrow is child of the character, and its pivot is on the starting point of the arrow.

by (3,493 points)
selected by

This works exactly like I wanted it to, thank you.

Glad to help!

0 votes

What I do is add the "arrow" node as a child to a "Direction" node and rotate the Direction node.

so set up like this:

Player
-Direction
--Arrow

Then offset Arrow to say 16 pixels to the right
when you want to rotate, rotate the Direction node. it will rotate but keep the offset

then you just have to remember that "right" is the default direction, so rotation = 0. of course you could set the offset to whatever makes more sense for your game, maybe "up" is the more natural default direction

by (14 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.