mirror of
https://github.com/Relintai/pandemonium_demo_projects.git
synced 2024-12-21 13:56:50 +01:00
Added navlink demos.
This commit is contained in:
parent
3fc3933921
commit
9dc8dd2036
74
2d/navigation_links/Node2D.tscn
Normal file
74
2d/navigation_links/Node2D.tscn
Normal file
@ -0,0 +1,74 @@
|
||||
[gd_scene load_steps=7 format=2]
|
||||
|
||||
[ext_resource path="res://navigation.gd" type="Script" id=1]
|
||||
[ext_resource path="res://icon.png" type="Texture" id=2]
|
||||
|
||||
[sub_resource type="NavigationPolygon" id=1]
|
||||
vertices = PoolVector2Array( 194, -109, 123, 99, -49, 219, -142, -40, -83, -133 )
|
||||
polygons = [ PoolIntArray( 0, 1, 2, 3, 4 ) ]
|
||||
outlines = [ PoolVector2Array( -83, -133, 194, -109, 123, 99, -49, 219, -142, -40 ) ]
|
||||
baked_outlines = [ PoolVector2Array( 194, -109, 123, 99, -49, 219, -142, -40, -83, -133 ) ]
|
||||
|
||||
[sub_resource type="NavigationPolygon" id=2]
|
||||
vertices = PoolVector2Array( 78, 44, 97, 249, -146, 41, -110, -85, 169, -149 )
|
||||
polygons = [ PoolIntArray( 0, 1, 2, 3 ), PoolIntArray( 3, 4, 0 ) ]
|
||||
outlines = [ PoolVector2Array( -110, -85, 169, -149, 78, 44, 97, 249, -146, 41 ) ]
|
||||
baked_outlines = [ PoolVector2Array( 78, 44, 97, 249, -146, 41, -110, -85, 169, -149 ) ]
|
||||
|
||||
[sub_resource type="NavigationPolygon" id=3]
|
||||
vertices = PoolVector2Array( 75, -11, -65, 113, -147, 69, -142, -44, 50, -72 )
|
||||
polygons = [ PoolIntArray( 0, 1, 2, 3, 4 ) ]
|
||||
outlines = [ PoolVector2Array( -65, 113, 75, -11, 50, -72, -142, -44, -147, 69 ) ]
|
||||
baked_outlines = [ PoolVector2Array( 75, -11, -65, 113, -147, 69, -142, -44, 50, -72 ) ]
|
||||
|
||||
[sub_resource type="NavigationPolygon" id=4]
|
||||
vertices = PoolVector2Array( 205, -11, 71, 128, -178, 79, -88, -97 )
|
||||
polygons = [ PoolIntArray( 0, 1, 2, 3 ) ]
|
||||
outlines = [ PoolVector2Array( -88, -97, 205, -11, 71, 128, -178, 79 ) ]
|
||||
baked_outlines = [ PoolVector2Array( 205, -11, 71, 128, -178, 79, -88, -97 ) ]
|
||||
|
||||
[node name="Node2D" type="Node2D"]
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="NavigationPolygonInstance" type="NavigationPolygonInstance" parent="."]
|
||||
navpoly = SubResource( 1 )
|
||||
|
||||
[node name="NavigationLink2D" type="NavigationLink2D" parent="."]
|
||||
position = Vector2( 188, 27 )
|
||||
start_position = Vector2( -100, 0 )
|
||||
end_position = Vector2( 200, 0 )
|
||||
|
||||
[node name="NavigationPolygonInstance2" type="NavigationPolygonInstance" parent="."]
|
||||
position = Vector2( 432, 65 )
|
||||
navpoly = SubResource( 2 )
|
||||
|
||||
[node name="NavigationLink2D2" type="NavigationLink2D" parent="."]
|
||||
position = Vector2( 452, 325 )
|
||||
start_position = Vector2( 0, -100 )
|
||||
end_position = Vector2( 0, 100 )
|
||||
|
||||
[node name="NavigationPolygonInstance3" type="NavigationPolygonInstance" parent="."]
|
||||
position = Vector2( 106, 271 )
|
||||
navpoly = SubResource( 3 )
|
||||
|
||||
[node name="NavigationLink2D3" type="NavigationLink2D" parent="."]
|
||||
position = Vector2( 136, 371 )
|
||||
start_position = Vector2( 100, 0 )
|
||||
end_position = Vector2( -100, 0 )
|
||||
|
||||
[node name="NavigationPolygonInstance4" type="NavigationPolygonInstance" parent="."]
|
||||
position = Vector2( 309, 434 )
|
||||
navpoly = SubResource( 4 )
|
||||
|
||||
[node name="NavigationLink2D4" type="NavigationLink2D" parent="."]
|
||||
position = Vector2( 57, 184 )
|
||||
start_position = Vector2( 0, -100 )
|
||||
end_position = Vector2( 0, 100 )
|
||||
|
||||
[node name="Character" type="Sprite" parent="."]
|
||||
position = Vector2( 64, -52 )
|
||||
texture = ExtResource( 2 )
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="."]
|
||||
position = Vector2( 298, 216 )
|
||||
zoom = Vector2( 1.752, 1.752 )
|
7
2d/navigation_links/default_env.tres
Normal file
7
2d/navigation_links/default_env.tres
Normal file
@ -0,0 +1,7 @@
|
||||
[gd_resource type="Environment3D" load_steps=2 format=2]
|
||||
|
||||
[sub_resource type="ProceduralSky" id=1]
|
||||
|
||||
[resource]
|
||||
background_mode = 2
|
||||
background_sky = SubResource( 1 )
|
BIN
2d/navigation_links/icon.png
Normal file
BIN
2d/navigation_links/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
35
2d/navigation_links/icon.png.import
Normal file
35
2d/navigation_links/icon.png.import
Normal file
@ -0,0 +1,35 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://icon.png"
|
||||
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.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
|
||||
process/normal_map_invert_y=false
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=true
|
||||
svg/scale=1.0
|
47
2d/navigation_links/navigation.gd
Normal file
47
2d/navigation_links/navigation.gd
Normal file
@ -0,0 +1,47 @@
|
||||
extends Node2D
|
||||
|
||||
export(float) var character_speed = 400.0
|
||||
var path = []
|
||||
|
||||
onready var character = $Character
|
||||
|
||||
func _process(delta):
|
||||
var walk_distance = character_speed * delta
|
||||
move_along_path(walk_distance)
|
||||
|
||||
|
||||
# The "click" event is a custom input action defined in
|
||||
# Project > Project Settings > Input Map tab.
|
||||
func _unhandled_input(event):
|
||||
if not event.is_action_pressed("click"):
|
||||
return
|
||||
|
||||
_update_navigation_path(character.position, get_local_mouse_position())
|
||||
|
||||
|
||||
func move_along_path(distance):
|
||||
var last_point = character.position
|
||||
while path.size():
|
||||
var distance_between_points = last_point.distance_to(path[0])
|
||||
# The position to move to falls between two points.
|
||||
if distance <= distance_between_points:
|
||||
character.position = last_point.linear_interpolate(path[0], distance / distance_between_points)
|
||||
return
|
||||
# The position is past the end of the segment.
|
||||
distance -= distance_between_points
|
||||
last_point = path[0]
|
||||
path.remove(0)
|
||||
# The character reached the end of the path.
|
||||
character.position = last_point
|
||||
set_process(false)
|
||||
|
||||
|
||||
func _update_navigation_path(start_position, end_position):
|
||||
# get_simple_path is part of the Navigation2D class.
|
||||
# It returns a PoolVector2Array of points that lead you
|
||||
# from the start_position to the end_position.
|
||||
path = Navigation2DServer.map_get_path(get_world_2d().navigation_map, start_position, end_position, true)
|
||||
# The first point is always the start_position.
|
||||
# We don't need it in this example as it corresponds to the character's position.
|
||||
path.remove(0)
|
||||
set_process(true)
|
33
2d/navigation_links/project.pandemonium
Normal file
33
2d/navigation_links/project.pandemonium
Normal file
@ -0,0 +1,33 @@
|
||||
; Engine configuration file.
|
||||
; It's best edited using the editor UI and not directly,
|
||||
; since the parameters that go here are not all obvious.
|
||||
;
|
||||
; Format:
|
||||
; [section] ; section goes between []
|
||||
; param=value ; assign values to parameters
|
||||
|
||||
config_version=4
|
||||
|
||||
[application]
|
||||
|
||||
config/name="Navigation Links"
|
||||
run/main_scene="res://Node2D.tscn"
|
||||
config/icon="res://icon.png"
|
||||
|
||||
[input]
|
||||
|
||||
click={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":1,"pressed":false,"doubleclick":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[physics]
|
||||
|
||||
common/enable_pause_aware_picking=true
|
||||
|
||||
[rendering]
|
||||
|
||||
vram_compression/import_etc=true
|
||||
vram_compression/import_etc2=false
|
||||
environment/default_environment="res://default_env.tres"
|
16
3d/navigation_links/README.md
Normal file
16
3d/navigation_links/README.md
Normal file
@ -0,0 +1,16 @@
|
||||
# 3D Navigation Mesh
|
||||
|
||||
Navigation mesh demo for 3D scenes, with a character
|
||||
able to pathfind around a complex 3D environment.
|
||||
The navigation path is drawn using a line.
|
||||
Code is provided for polyline following in 3D.
|
||||
|
||||
Language: GDScript
|
||||
|
||||
Renderer: GLES 3
|
||||
|
||||
Check out this demo on the asset library: https://godotengine.org/asset-library/asset/124
|
||||
|
||||
## Screenshots
|
||||
|
||||
![Screenshot](screenshots/nav.png)
|
9
3d/navigation_links/default_env.tres
Normal file
9
3d/navigation_links/default_env.tres
Normal file
@ -0,0 +1,9 @@
|
||||
[gd_resource type="Environment3D" load_steps=2 format=2]
|
||||
|
||||
[sub_resource type="ProceduralSky" id=1]
|
||||
ground_horizon_color = Color( 0.156863, 0.184314, 0.211765, 1 )
|
||||
|
||||
[resource]
|
||||
background_mode = 2
|
||||
background_sky = SubResource( 1 )
|
||||
ssao_blur = 1
|
BIN
3d/navigation_links/icon.png
Normal file
BIN
3d/navigation_links/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.6 KiB |
35
3d/navigation_links/icon.png.import
Normal file
35
3d/navigation_links/icon.png.import
Normal file
@ -0,0 +1,35 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://icon.png"
|
||||
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.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
|
||||
process/normal_map_invert_y=false
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=true
|
||||
svg/scale=1.0
|
88
3d/navigation_links/navmesh.gd
Normal file
88
3d/navigation_links/navmesh.gd
Normal file
@ -0,0 +1,88 @@
|
||||
extends Spatial
|
||||
|
||||
const SPEED = 10.0
|
||||
|
||||
var camrot = 0.0
|
||||
var m = SpatialMaterial.new()
|
||||
|
||||
var path = []
|
||||
var show_path = true
|
||||
|
||||
onready var robot = get_node("RobotBase")
|
||||
onready var camera = get_node("CameraBase/Camera")
|
||||
|
||||
func _ready():
|
||||
set_process_input(true)
|
||||
m.flags_unshaded = true
|
||||
m.flags_use_point_size = true
|
||||
m.albedo_color = Color.white
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
var direction = Vector3()
|
||||
|
||||
# We need to scale the movement speed by how much delta has passed,
|
||||
# otherwise the motion won't be smooth.
|
||||
var step_size = delta * SPEED
|
||||
|
||||
if path.size() > 0:
|
||||
# Direction is the difference between where we are now
|
||||
# and where we want to go.
|
||||
var destination = path[0]
|
||||
direction = destination - robot.translation
|
||||
|
||||
# If the next node is closer than we intend to 'step', then
|
||||
# take a smaller step. Otherwise we would go past it and
|
||||
# potentially go through a wall or over a cliff edge!
|
||||
if step_size > direction.length():
|
||||
step_size = direction.length()
|
||||
# We should also remove this node since we're about to reach it.
|
||||
path.remove(0)
|
||||
|
||||
# Move the robot towards the path node, by how far we want to travel.
|
||||
# Note: For a KinematicBody, we would instead use move_and_slide
|
||||
# so collisions work properly.
|
||||
robot.translation += direction.normalized() * step_size
|
||||
|
||||
# Lastly let's make sure we're looking in the direction we're traveling.
|
||||
# Clamp y to 0 so the robot only looks left and right, not up/down.
|
||||
direction.y = 0
|
||||
if direction:
|
||||
# Direction is relative, so apply it to the robot's location to
|
||||
# get a point we can actually look at.
|
||||
var look_at_point = robot.translation + direction.normalized()
|
||||
# Make the robot look at the point.
|
||||
robot.look_at(look_at_point, Vector3.UP)
|
||||
|
||||
|
||||
func _unhandled_input(event):
|
||||
if event is InputEventMouseButton and event.button_index == BUTTON_LEFT and event.pressed:
|
||||
var from = camera.project_ray_origin(event.position)
|
||||
var to = from + camera.project_ray_normal(event.position) * 1000
|
||||
var target_point = NavigationServer.map_get_closest_point_to_segment(get_world_3d().navigation_map, from, to)
|
||||
|
||||
# Set the path between the robots current location and our target.
|
||||
path = NavigationServer.map_get_path(get_world_3d().navigation_map, robot.translation, target_point, true)
|
||||
|
||||
if show_path:
|
||||
draw_path(path)
|
||||
|
||||
if event is InputEventMouseMotion:
|
||||
if event.button_mask & (BUTTON_MASK_MIDDLE + BUTTON_MASK_RIGHT):
|
||||
camrot += event.relative.x * 0.005
|
||||
get_node("CameraBase").set_rotation(Vector3(0, camrot, 0))
|
||||
print("Camera Rotation: ", camrot)
|
||||
|
||||
|
||||
func draw_path(path_array):
|
||||
var im = get_node("Draw")
|
||||
im.set_material_override(m)
|
||||
im.clear()
|
||||
im.begin(Mesh.PRIMITIVE_POINTS, null)
|
||||
im.add_vertex(path_array[0])
|
||||
im.add_vertex(path_array[path_array.size() - 1])
|
||||
im.end()
|
||||
im.begin(Mesh.PRIMITIVE_LINE_STRIP, null)
|
||||
for x in path:
|
||||
im.add_vertex(x)
|
||||
im.end()
|
143
3d/navigation_links/navmesh.tscn
Normal file
143
3d/navigation_links/navmesh.tscn
Normal file
File diff suppressed because one or more lines are too long
BIN
3d/navigation_links/particle.png
Normal file
BIN
3d/navigation_links/particle.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 129 B |
37
3d/navigation_links/particle.png.import
Normal file
37
3d/navigation_links/particle.png.import
Normal file
@ -0,0 +1,37 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path.s3tc="res://.import/particle.png-c2ba3d91e96c62035d672392a1197218.s3tc.stex"
|
||||
path.etc="res://.import/particle.png-c2ba3d91e96c62035d672392a1197218.etc.stex"
|
||||
metadata={
|
||||
"imported_formats": [ "s3tc", "etc" ],
|
||||
"vram_texture": true
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://particle.png"
|
||||
dest_files=[ "res://.import/particle.png-c2ba3d91e96c62035d672392a1197218.s3tc.stex", "res://.import/particle.png-c2ba3d91e96c62035d672392a1197218.etc.stex" ]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=2
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_mode=0
|
||||
compress/bptc_ldr=0
|
||||
compress/normal_map=0
|
||||
flags/repeat=true
|
||||
flags/filter=true
|
||||
flags/mipmaps=true
|
||||
flags/anisotropic=false
|
||||
flags/srgb=1
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/HDR_as_SRGB=false
|
||||
process/invert_color=false
|
||||
process/normal_map_invert_y=false
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=false
|
||||
svg/scale=1.0
|
31
3d/navigation_links/project.pandemonium
Normal file
31
3d/navigation_links/project.pandemonium
Normal file
@ -0,0 +1,31 @@
|
||||
; Engine configuration file.
|
||||
; It's best edited using the editor UI and not directly,
|
||||
; since the parameters that go here are not all obvious.
|
||||
;
|
||||
; Format:
|
||||
; [section] ; section goes between []
|
||||
; param=value ; assign values to parameters
|
||||
|
||||
config_version=4
|
||||
|
||||
[application]
|
||||
|
||||
config/name="3D Navigation Links"
|
||||
config/description="Navigation mesh demo for 3D scenes, with a character
|
||||
able to pathfind around a complex 3D environment.
|
||||
The navigation path is drawn using a line.
|
||||
Code is provided for polyline following in 3D."
|
||||
run/main_scene="res://navmesh.tscn"
|
||||
config/icon="res://icon.png"
|
||||
|
||||
[gdnative]
|
||||
|
||||
singletons=[ ]
|
||||
|
||||
[rendering]
|
||||
|
||||
quality/intended_usage/framebuffer_allocation=3
|
||||
vram_compression/import_etc=true
|
||||
vram_compression/import_etc2=false
|
||||
quality/shadows/filter_mode=2
|
||||
quality/filters/msaa=2
|
0
3d/navigation_links/screenshots/.gdignore
Normal file
0
3d/navigation_links/screenshots/.gdignore
Normal file
BIN
3d/navigation_links/screenshots/nav.png
Normal file
BIN
3d/navigation_links/screenshots/nav.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 21 KiB |
Loading…
Reference in New Issue
Block a user