diff options
author | Juan Linietsky <reduzio@gmail.com> | 2014-11-19 11:33:15 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2014-11-19 11:33:15 -0300 |
commit | e709468bb13e795cff72b3e87198c61c5b1a2ee7 (patch) | |
tree | 11d4a855259498bdaf10719199b506034a802536 /demos/3d | |
parent | d5cb758d36035fc35e960a466d0b370ff19e4f76 (diff) |
missing navmesh demo and small fixes
Diffstat (limited to 'demos/3d')
-rw-r--r-- | demos/3d/navmesh/engine.cfg | 9 | ||||
-rw-r--r-- | demos/3d/navmesh/navmesh.gd | 110 | ||||
-rw-r--r-- | demos/3d/navmesh/navmesh.scn | bin | 0 -> 37856 bytes | |||
-rw-r--r-- | demos/3d/navmesh/particle.png | bin | 0 -> 260 bytes |
4 files changed, 119 insertions, 0 deletions
diff --git a/demos/3d/navmesh/engine.cfg b/demos/3d/navmesh/engine.cfg new file mode 100644 index 0000000000..30af6ce5a5 --- /dev/null +++ b/demos/3d/navmesh/engine.cfg @@ -0,0 +1,9 @@ +[application] + +name="Navmesh Demo" +main_scene="res://navmesh.scn" +icon="res://icon.png" + +[rasterizer] + +shadow_filter=3 diff --git a/demos/3d/navmesh/navmesh.gd b/demos/3d/navmesh/navmesh.gd new file mode 100644 index 0000000000..a81a5e90d6 --- /dev/null +++ b/demos/3d/navmesh/navmesh.gd @@ -0,0 +1,110 @@ + +extends Navigation + +# member variables here, example: +# var a=2 +# var b="textvar" + +const SPEED=4.0 + +var camrot=0.0 + +var begin=Vector3() +var end=Vector3() +var m = FixedMaterial.new() + +var path=[] + +func _process(delta): + + + if (path.size()>1): + + var to_walk = delta*SPEED + var to_watch = Vector3(0,1,0) + while(to_walk>0 and path.size()>=2): + var pfrom = path[path.size()-1] + var pto = path[path.size()-2] + to_watch = (pto - pfrom).normalized() + var d = pfrom.distance_to(pto) + if (d<=to_walk): + path.remove(path.size()-1) + to_walk-=d + else: + path[path.size()-1] = pfrom.linear_interpolate(pto,to_walk/d) + to_walk=0 + + var atpos = path[path.size()-1] + var atdir = to_watch + atdir.y=0 + + var t = Transform() + t.origin=atpos + t=t.looking_at(atpos+atdir,Vector3(0,1,0)) + get_node("robot_base").set_transform(t) + + if (path.size()<2): + path=[] + set_process(false) + + else: + set_process(false) + +var draw_path=false + +func _update_path(): + + var p = get_simple_path(begin,end,true) + path=Array(p) # Vector3array to complex to use, convert to regular array + path.invert() + set_process(true) + + if (draw_path): + var im = get_node("draw") + im.set_material_override(m) + im.clear() + im.begin(Mesh.PRIMITIVE_POINTS,null) + im.add_vertex(begin) + im.add_vertex(end) + im.end() + im.begin(Mesh.PRIMITIVE_LINE_STRIP,null) + for x in p: + im.add_vertex(x) + im.end() + +func _input(ev): + + if (ev.type==InputEvent.MOUSE_BUTTON and ev.button_index==BUTTON_LEFT and ev.pressed): + + var from = get_node("cambase/Camera").project_position(ev.pos) + var to = from+get_node("cambase/Camera").project_ray_normal(ev.pos)*100 + var p = get_closest_point_to_segment(from,to) + + begin=get_closest_point(get_node("robot_base").get_translation()) + end=p + + _update_path() + + if (ev.type==InputEvent.MOUSE_MOTION): + if (ev.button_mask&BUTTON_MASK_MIDDLE): + + camrot+=ev.relative_x*0.005 + get_node("cambase").set_rotation(Vector3(0,camrot,0)) + print("camrot ", camrot) + + + +func _ready(): + # Initalization here + set_process_input(true) + m.set_line_width(3) + m.set_point_size(3) + m.set_fixed_flag(FixedMaterial.FLAG_USE_POINT_SIZE,true) + m.set_flag(Material.FLAG_UNSHADED,true) + #begin = get_closest_point(get_node("start").get_translation()) + #end = get_closest_point(get_node("end").get_translation()) + #call_deferred("_update_path") + + pass + + diff --git a/demos/3d/navmesh/navmesh.scn b/demos/3d/navmesh/navmesh.scn Binary files differnew file mode 100644 index 0000000000..73df340b1e --- /dev/null +++ b/demos/3d/navmesh/navmesh.scn diff --git a/demos/3d/navmesh/particle.png b/demos/3d/navmesh/particle.png Binary files differnew file mode 100644 index 0000000000..18851c8c9d --- /dev/null +++ b/demos/3d/navmesh/particle.png |