0 votes

I just got the player movement to work like left and right rotate and up moves you in the direction you're facing so I just need to figure out how to get the lasers to fire in the same direction that you're currently facing. I tried to use position2d node but couldn't get it to work in the shoot functions because I have it located in a separate scene from the player.

Godot version 3.3.2
in Engine by (17 points)

1 Answer

+1 vote

There is a good example in the Godot documentation. The key is sending the angle of your player to the bullet when it first spawns.
https://docs.godotengine.org/en/latest/tutorials/physics/using_kinematic_body_2d.html

by (62 points)

https://github.com/LuckyCanary/AsteroidGame/tree/main

So, I tried to follow the Godot documentation you suggested and I managed to have the laser spawn at the end of my ship in whatever direction it's facing but now the lasers shoot to the right of my ship instead of from the front of it. Any ideas? I've posted the code to my player and laser.

Here is a screenshot of the laser shooting sideways as you can see, it spawns out of the Muzzle like I want it too though

https://github.com/LuckyCanary/AsteroidGame/blob/main/AsteroidGame.png

https://github.com/LuckyCanary/AsteroidGame/blob/main/asteroidgame2.png

As you can see it changes directions based on the player's rotation but it just shoots to the right of the ship instead of to the top

EDIT: Also, for some reason now when I get a game over and restart the game, the game will crash when I try to shoot my laser and give me an error of null instance

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.