How to rotate laser "bullet" scene equal to rotation of player?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By 1dominator11
:warning: Old Version Published before Godot 3 was released.

I’m making a local multiplayer top down shooter game as my first ever Godot game.
Player One moves using WASD and shoots using the space bar. You move in degrees of 45, and I’ve succesfully been able to get the player to move and shoot the laser forward at the correct angle.

However, I don’t know how to get the laser to be in the same orientation as the player. I’ve tried things like creating a global variable for the player node and using that in my laser script to get the rotation of that node, but that didn’t work.

I also tried doing something like (sorry if code is wrong I’m just remembering off the top of my head)
set_rotd(get_rotd(get_parent().get_node("player1")))
but because of how the laser is instanced, it’s technically a child of the main node, not the player1 node.

I couldn’t find anything online specific enough for my case (unless I just didn’t look hard enough), so I wanted to get some help here.

If I need to elaborate more, let me know.

:bust_in_silhouette: Reply From: avencherus

Would have to know more about the implementation of your projectile.

Generally though you could store a player’s heading from whichever vector you’re using to get the angle from. The heading should be a normalized vector, and from there you can apply whatever length you like or use it to create velocity vectors for projectiles.

if(velocity.length() > min_movement_speed): heading = velocity.normalized()

Then you might test it in canvas drawing _draw() during update().

draw_line(player.get_pos(), player.get_pos() + player.heading * laser_length, Color(1,0,0), 5)