The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

+1 vote

I'm creating a laser effect based on drawing a Line2D. It's a board element that has a fixed start and end location. I used a 32x32 sprite, where the laser port is halfway down one side of the sprite and should shoot across the sprite maybe across more than just the sprite itself.

When I'm not shooting I remove the points from the Line2D - perfect the laser line disappears. But when I use Vector2D(16,0) as the start point the line starts in the middle of my sprite. Some experimentation says I need (-8,0) as the start point.

Where does this magic number -8 come from when my sprite is 32x32?

The second endpoint to create a horizontal line that spans the sprite length turns out to be (16,0). Why is the distance only 24 rather than my expected 32?

My sprite is 32x32 and covers 4 grid points by 4 grid points in the 2D editor.

What concept am I missing?

in Engine by (34 points)
edited by

1 Answer

0 votes

The origin of the Line2D should be at the same global position as the origin of its parent, which in this case seems to be the Sprite. The origin of the Sprite is usually its center. My guess is the sprite's origin is slightly off. Try using the icon just to the left of the hand icon at the top of the scene viewport to adjust it.

Hope this helps!

by (130 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.