Dot product Siding

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By blackmumba
:warning: Old Version Published before Godot 3 was released.

i try to understand but i stuck on this chapter
How can i get Vector F or i have to create by myself like raycast

reference document

Please excuse my poor English.
Thank you.

:bust_in_silhouette: Reply From: Zylann

In the doc, F can be any direction. It’s simply where the enemy looks at. In this example, dot product allows you to tell how good B can see A, assuming there is no obstacle in the level. Good ol’ vector math :stuck_out_tongue:

If B is a Node2D (or any subtype of it), and is designed so that its sprite looks on the right, you can get F like this:

var F = B.get_global_transform().x

If B’s sprite is designed to look down:

var F = B.get_global_transform().y

(Note that the 2D engine Y axis is pointing down, not up)