0 votes

I'm making a top down shooter where enemies have a field of vision. If the player enters the FOV of the enemy, the enemy runs to the player. I'm having trouble with making the FOV work properly. The way my FOV system is supposed to work is the enemy uses the dot product to figure out if the player is in front of the enemy. If yes, then the enemy shoots a ray towards the player to check if there isn't anything blocking the view to the player. My problem is I can't figure out how to get the facing direction of the enemy that is supposed to be used to figure if the player is in front of the enemy in the dot product. I have tried a lot of things and nothing works so far.

in Engine by (18 points)

1 Answer

+1 vote
Best answer

you mean the the orientation vector of the KinematicBody?

var forward_vector = Vector2(0,1)
var the_object = self
var orientation_global = (the_object.to_global( forward_vector ) - the_object.global_position)

i make a vector pointing one unit to the front of the object and transform them to global space. Then subtract the offset (object position). Then you have a vector from world origin one unit in facing direction,

by (4,084 points)
selected by

This worked for me, thank you.

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.