+2 votes

Hello everyone! Im developing a 2D rogue-like game and came up with the following predicament:

Im doing a weapon that shoots a laser-like beam that attaches itself to either the second player or the enemy (Both KinematicBodies here), and keep both ends connected while doing damage to whatever comes in contact with it and has a certain tag (enemies). The player and enemies can move, so the line has to acompany that movement (might change either direction, distance, etc...)

...That was the plan, but i have no idea on how to approach this. In Unity i suppose i could use Line Renderer to put a texture on the line, and work via code with two Vector2 positions to apply damage and conect the line begining and end. Is that possible in Godot?

I know about the Draw() function, but a simple line with solid color is not exactly what i am lookin for here. Maybe a particle emmiter in order to produce the lightning effect?

Does anybody have a suggestion..? Thanks in advance!

asked Sep 12, 2018 in Engine by jim (32 points)

2 Answers

+2 votes

Godot has a "line" tool for this if it is 2D. The line tool also takes textures.

If it is 3D then you will have to make your own tool. Stretching a polygon for the effect would be the quickest way.

answered Sep 12, 2018 by MysteryGM (1,428 points)

Yeah I've found about the Line2D node later (the project is 2D), but its my understanding that the line just uses a static Texture? I was also lookin into a way of adding noise to it (be it lightning, laser beam, anything). Another user suggested using Shaders. Will look into it, but if anybody got any more references, I would certainly welcome it.

Thanks man!

Also, the Line2D tool doesnt have a collision inner working, so I would guess i need to make instances of Area2D nodes that accompany each Vector2 along the Line2D that do the damage...? or is there an easier way of implementing this?

A raycast would be faster. Check from point to point or from start to end.

+3 votes
answered Sep 13, 2018 by golpebaixo (34 points)

Awesome! yesterday I've found a similar implementation of this shader (Using Texture Rect), but when i tried applying it to the Line2D node, something went wrong... I've got no experience working with shaders, so maybe i need to research this some more. Dont know if there is a more specific way to implement this on a line that I'm missing.

Thanks for the link! I really apreciate the help!

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 How to use this Q&A? before posting your first questions.