+1 vote

I am not sure how to approach this. I am trying to make a 2D top down game, but I am not sure how to get the bullet to shoot at the direction where the player is facing at. I looked up some stuff on google, but I am still confused. Can someone give me some hints on how to approach this? Thank you.

This is a post I found on reddit that seems really helpful, but one part is confusing for me:
"So a simple overview of what you need to do would be:

create a bullet scene, which consists of a kinematic body (named "bullet"), with a sprite and a collision body2d as children. add it to the group "bullets"

add a bullet script to your bullet node. It will be responsible for moving your bullet along a specified direction, which is a Vector2. In process you'll do something like move(direction * speed* delta). You can also add a killbullet function that will remove your bullet if it hits a wall, goes off screen, etc...

in your player script, when you hit the fire button, instantiate a new bullet and set its direction to the same direction as the player.

have your enemies look for collision with a body in group "bullets", and take damage accordingly."

The part I am not sure what to do is how do I instantiate a bullet and tell it the direction the player is facing? Thank you for helping me out.

in Engine by (26 points)

1 Answer

+3 votes
Best answer

check out this tutorial of youtube channel KidsCanCode

https://www.youtube.com/watch?v=UKfzBnfh4Ak&list=PLsk-HSGFjnaFC8kEv6MaLXnnDcevGpSWf&index=4

This will explain how you can fire bullet where user is facing.

by (123 points)
selected by

[comment deleted - thought you were talking about 3d]
Link here https://docs.godotengine.org/en/3.1/tutorials/3d/fps_tutorial/index.html

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.
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 webmaster@godotengine.org with your username.