-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* First commit * Update readme with iamges
- Loading branch information
1 parent
c10de54
commit 864a1d4
Showing
33 changed files
with
599 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
# Godot-specific ignores | ||
.import/ | ||
export.cfg | ||
export_presets.cfg | ||
|
||
# Imported translations (automatically generated from CSV files) | ||
*.translation | ||
|
||
# Mono-specific ignores | ||
.mono/ | ||
data_*/ | ||
mono_crash.*.json | ||
|
||
# System/tool-specific ignores | ||
.directory | ||
*~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,31 @@ | ||
# godot-field-of-view | ||
Godot FOV (Field of View) | ||
|
||
Godot FOV (Field of View). | ||
|
||
Godot script that allow use of Field of View in (currently) 2d game. | ||
|
||
## Features | ||
|
||
1. Highly customizable | ||
1. Multiple targets | ||
1. Targets defined by groups | ||
1. Precision can be defined | ||
|
||
## Current State | ||
|
||
 | ||
 | ||
 | ||
 | ||
 | ||
 | ||
 | ||
 | ||
|
||
## Variables | ||
|
||
 | ||
|
||
# Credits / Links | ||
|
||
Code forked from https://github.com/luisboch/godot_field_of_view |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v1.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
extends Node2D | ||
|
||
export(float) var field_of_view: float = 60.0 | ||
export(float) var radius_warn: float = 500.0 | ||
export(float) var radius_danger: float = 200.0 | ||
export(float) var view_detail: float = 60.0 | ||
|
||
export(bool) var show_circle: bool = false | ||
export(bool) var show_fov: bool = true | ||
export(bool) var show_target_line: bool = true | ||
|
||
export(Color) var circle_color: Color = Color("#9f185c0b") | ||
export(Color) var fov_color: Color = Color("#b23d7f0b") | ||
export(Color) var fov_warn_color: Color = Color("#b1eedf0b") | ||
export(Color) var fov_danger_color: Color = Color("#9dfb320b") | ||
|
||
export(Array) var enemy_groups: Array = ["Enemy"] | ||
|
||
var in_danger_area: Array = [] | ||
var in_warn_area: Array = [] | ||
|
||
# Buffer to target points | ||
var points_arc: Array = [] | ||
var is_update: bool = false | ||
|
||
func _process(delta: float) -> void: | ||
is_update = true | ||
check_view() | ||
update() | ||
|
||
func _draw() -> void: | ||
if show_circle: | ||
draw_circle(get_position(), radius_warn, circle_color) | ||
|
||
if show_fov && is_update: | ||
draw_circle_arc() | ||
|
||
func draw_circle_arc() -> void: | ||
for aux in points_arc: | ||
if aux.level == 1 && show_target_line: | ||
draw_line(get_position(), aux.pos, fov_warn_color, 3) | ||
elif aux.level == 2 && show_target_line: | ||
draw_line(get_position(), aux.pos, fov_danger_color, 5) | ||
else: | ||
draw_line(get_position(), aux.pos, fov_color) | ||
|
||
func deg_to_vector(deg: float) -> Vector2: | ||
return Vector2(cos(deg2rad(deg)), sin(deg2rad(deg))) | ||
|
||
func check_view() -> void: | ||
var dir_deg = rad2deg(transform.get_rotation()) | ||
var start_angle = dir_deg - (field_of_view * 0.5) | ||
var end_angle = start_angle + field_of_view | ||
|
||
points_arc = [] | ||
in_danger_area = [] | ||
in_warn_area = [] | ||
|
||
var space_state = get_world_2d().direct_space_state | ||
|
||
for i in range(view_detail + 1): | ||
var cur_angle = start_angle + (i * (field_of_view / view_detail)) + 90 | ||
var point = get_position() + deg_to_vector(cur_angle) * radius_warn | ||
|
||
# use global coordinates, not local to node | ||
var result = space_state.intersect_ray(get_global_transform().origin, to_global(point), [get_parent()]) | ||
|
||
if result.empty(): | ||
points_arc.append({"pos": point, "level": 0}) | ||
continue | ||
|
||
var local_pos = to_local(result.position) | ||
var dist = get_position().distance_to(local_pos) | ||
var level = 0 | ||
var is_enemy = false | ||
|
||
if in_danger_area.has(result.collider) || in_warn_area.has(result.collider): | ||
points_arc.append({"pos": local_pos, "level": level}) | ||
continue | ||
|
||
for g in enemy_groups : | ||
if result.collider.get_groups().has(g): | ||
is_enemy = true | ||
|
||
if !is_enemy: | ||
points_arc.append({"pos": local_pos, "level": level}) | ||
continue | ||
|
||
level = 1 | ||
|
||
if dist < radius_danger : | ||
level = 2 | ||
in_danger_area.append(result.collider) | ||
else : | ||
in_warn_area.append(result.collider) | ||
|
||
# check if directly to target, we can "shoot" | ||
var tgt_pos = result.collider.get_global_transform().origin | ||
var this_pos = get_global_transform().origin | ||
var tgt_dir = (tgt_pos - this_pos).normalized() | ||
var view_angle = rad2deg(deg_to_vector(rad2deg(get_global_transform().get_rotation())+90).angle_to(tgt_dir)) | ||
|
||
if !(view_angle > start_angle && view_angle < end_angle): | ||
points_arc.append({"pos": local_pos, "level": level}) | ||
continue | ||
|
||
var result2 = space_state.intersect_ray(this_pos, tgt_pos, [get_parent()]) | ||
|
||
if !result2.empty() && result2.collider == result.collider : | ||
# we can, then use this as line | ||
points_arc.append({"pos": local_pos, "level": 0}) | ||
if show_target_line: | ||
points_arc.append({"pos": to_local(tgt_pos), "level": level}) | ||
else : | ||
points_arc.append({"pos": local_pos, "level": level}) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[remap] | ||
|
||
importer="texture" | ||
type="StreamTexture" | ||
path="res://.import/icon.png-bdeb6f1d69351700797d4b405d9d668f.stex" | ||
metadata={ | ||
"vram_texture": false | ||
} | ||
|
||
[deps] | ||
|
||
source_file="res://addons/fov/icon.png" | ||
dest_files=[ "res://.import/icon.png-bdeb6f1d69351700797d4b405d9d668f.stex" ] | ||
|
||
[params] | ||
|
||
compress/mode=0 | ||
compress/lossy_quality=0.7 | ||
compress/hdr_mode=0 | ||
compress/bptc_ldr=0 | ||
compress/normal_map=0 | ||
flags/repeat=0 | ||
flags/filter=true | ||
flags/mipmaps=false | ||
flags/anisotropic=false | ||
flags/srgb=2 | ||
process/fix_alpha_border=true | ||
process/premult_alpha=false | ||
process/HDR_as_SRGB=false | ||
process/invert_color=false | ||
stream=false | ||
size_limit=0 | ||
detect_3d=true | ||
svg/scale=1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[gd_resource type="Environment" load_steps=2 format=2] | ||
|
||
[sub_resource type="ProceduralSky" id=1] | ||
|
||
[resource] | ||
background_mode = 2 | ||
background_sky = SubResource( 1 ) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[remap] | ||
|
||
importer="texture" | ||
type="StreamTexture" | ||
path="res://.import/block-black.jpg-11d7c7b3d90feae94ca26a7e04604c51.stex" | ||
metadata={ | ||
"vram_texture": false | ||
} | ||
|
||
[deps] | ||
|
||
source_file="res://example/assets/block-black.jpg" | ||
dest_files=[ "res://.import/block-black.jpg-11d7c7b3d90feae94ca26a7e04604c51.stex" ] | ||
|
||
[params] | ||
|
||
compress/mode=0 | ||
compress/lossy_quality=0.7 | ||
compress/hdr_mode=0 | ||
compress/bptc_ldr=0 | ||
compress/normal_map=0 | ||
flags/repeat=0 | ||
flags/filter=true | ||
flags/mipmaps=false | ||
flags/anisotropic=false | ||
flags/srgb=2 | ||
process/fix_alpha_border=true | ||
process/premult_alpha=false | ||
process/HDR_as_SRGB=false | ||
process/invert_color=false | ||
stream=false | ||
size_limit=0 | ||
detect_3d=true | ||
svg/scale=1.0 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[remap] | ||
|
||
importer="texture" | ||
type="StreamTexture" | ||
path="res://.import/block-blue.jpg-bb29fa4996966e33d0b2408bec00ab43.stex" | ||
metadata={ | ||
"vram_texture": false | ||
} | ||
|
||
[deps] | ||
|
||
source_file="res://example/assets/block-blue.jpg" | ||
dest_files=[ "res://.import/block-blue.jpg-bb29fa4996966e33d0b2408bec00ab43.stex" ] | ||
|
||
[params] | ||
|
||
compress/mode=0 | ||
compress/lossy_quality=0.7 | ||
compress/hdr_mode=0 | ||
compress/bptc_ldr=0 | ||
compress/normal_map=0 | ||
flags/repeat=0 | ||
flags/filter=true | ||
flags/mipmaps=false | ||
flags/anisotropic=false | ||
flags/srgb=2 | ||
process/fix_alpha_border=true | ||
process/premult_alpha=false | ||
process/HDR_as_SRGB=false | ||
process/invert_color=false | ||
stream=false | ||
size_limit=0 | ||
detect_3d=true | ||
svg/scale=1.0 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[remap] | ||
|
||
importer="texture" | ||
type="StreamTexture" | ||
path="res://.import/block-green.jpg-177a94fa2f3da4dc18610029e5a2663b.stex" | ||
metadata={ | ||
"vram_texture": false | ||
} | ||
|
||
[deps] | ||
|
||
source_file="res://example/assets/block-green.jpg" | ||
dest_files=[ "res://.import/block-green.jpg-177a94fa2f3da4dc18610029e5a2663b.stex" ] | ||
|
||
[params] | ||
|
||
compress/mode=0 | ||
compress/lossy_quality=0.7 | ||
compress/hdr_mode=0 | ||
compress/bptc_ldr=0 | ||
compress/normal_map=0 | ||
flags/repeat=0 | ||
flags/filter=true | ||
flags/mipmaps=false | ||
flags/anisotropic=false | ||
flags/srgb=2 | ||
process/fix_alpha_border=true | ||
process/premult_alpha=false | ||
process/HDR_as_SRGB=false | ||
process/invert_color=false | ||
stream=false | ||
size_limit=0 | ||
detect_3d=true | ||
svg/scale=1.0 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[remap] | ||
|
||
importer="texture" | ||
type="StreamTexture" | ||
path="res://.import/block-white.jpg-22873ae34a4b3ead71548996605e0679.stex" | ||
metadata={ | ||
"vram_texture": false | ||
} | ||
|
||
[deps] | ||
|
||
source_file="res://example/assets/block-white.jpg" | ||
dest_files=[ "res://.import/block-white.jpg-22873ae34a4b3ead71548996605e0679.stex" ] | ||
|
||
[params] | ||
|
||
compress/mode=0 | ||
compress/lossy_quality=0.7 | ||
compress/hdr_mode=0 | ||
compress/bptc_ldr=0 | ||
compress/normal_map=0 | ||
flags/repeat=0 | ||
flags/filter=true | ||
flags/mipmaps=false | ||
flags/anisotropic=false | ||
flags/srgb=2 | ||
process/fix_alpha_border=true | ||
process/premult_alpha=false | ||
process/HDR_as_SRGB=false | ||
process/invert_color=false | ||
stream=false | ||
size_limit=0 | ||
detect_3d=true | ||
svg/scale=1.0 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[gd_scene load_steps=3 format=2] | ||
|
||
[ext_resource path="res://example/assets/block-black.jpg" type="Texture" id=1] | ||
|
||
[sub_resource type="RectangleShape2D" id=1] | ||
extents = Vector2( 42.0301, 40.1378 ) | ||
|
||
[node name="Block" type="StaticBody2D"] | ||
position = Vector2( 554.68, 103.442 ) | ||
collision_layer = 3 | ||
collision_mask = 3 | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] | ||
shape = SubResource( 1 ) | ||
|
||
[node name="Sprite" type="Sprite" parent="."] | ||
texture = ExtResource( 1 ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[gd_scene load_steps=3 format=2] | ||
|
||
[ext_resource path="res://example/assets/block-white.jpg" type="Texture" id=1] | ||
|
||
[sub_resource type="RectangleShape2D" id=1] | ||
extents = Vector2( 40.8181, 41.4788 ) | ||
|
||
[node name="Enemy1" type="KinematicBody2D" groups=[ | ||
"Enemy", | ||
]] | ||
position = Vector2( 409.473, 151.002 ) | ||
__meta__ = { | ||
"_edit_group_": true | ||
} | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] | ||
shape = SubResource( 1 ) | ||
|
||
[node name="Sprite" type="Sprite" parent="."] | ||
texture = ExtResource( 1 ) |
Oops, something went wrong.