0 votes

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.

in Engine by (12 points)

1 Answer

0 votes

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)

by (5,278 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.