0 votes

Hello there, I'm attempting my first go at developing a game and it's going to be a roguelike 2d bullet hell type game. I've seen many games like these already with a cursor system where the player shoots wherever the cursor is currently pointed. I was wondering if there was a way to remove the need for a cursor entirely and just have an auto targetting system that locks your aim at the nearest enemy visible in your line of sight.

Thank you in advance!

Godot version Version 3.5 standard
in Engine by (12 points)


if player.global_position.distance_to(enemy.global_position) < 10:
      print("bla bla")

10 = distance between player and enemy

1 Answer

0 votes

Hi, to get an enemy in front of the player we need to get an angle with a dot product

Maybe this sample code can help you ^_^
code example

-rotate without mouse
-rotate with mouse

by (84 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.