blob: 04c3ef1276d0bd02abcf81b19b49bf87ef34c729 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
extends Spatial
export(NodePath) var traveler = null
onready var _traveler = get_node(traveler)
export var acceleration = 10.0
onready var chunk_render_distance = $"ChunkRenderDistance"
onready var chunk_render_mid = $"ChunkRenderMid"
onready var chunk_render_close = $"ChunkRenderClose"
onready var lod_distance = chunk_render_distance.get_node("Radius").shape.radius
onready var lod_mid = chunk_render_mid.get_node("Radius").shape.radius
onready var lod_close = chunk_render_close.get_node("Radius").shape.radius
onready var chunk_half_size = $"Chunks/Chunk/Size".shape.radius
onready var chunk_size = chunk_half_size * 2.0
func _ready():
ChunkLoader.world = self
ChunkGen.chunk_half_size = self.chunk_half_size
func _on_ChunkRenderDistance_area_entered(area:Area):
if area.lod < area.LOD.DISTANCE:
area.lod = area.LOD.DISTANCE
area.lod_update()
func _on_ChunkRenderMid_area_entered(area:Area):
if area.lod < area.LOD.MID:
area.lod = area.LOD.MID
area.lod_update()
func _on_ChunkRenderClose_area_entered(area:Area):
if area.lod < area.LOD.CLOSE:
area.lod = area.LOD.CLOSE
area.lod_update()
func _on_ChunkRenderDistance_area_exited(area:Area):
free_chunk(area)
func _on_ChunkRenderMid_area_exited(area:Area):
area.lod = area.LOD.DISTANCE
area.lod_update()
func _on_ChunkRenderClose_area_exited(area:Area):
area.lod = area.LOD.MID
area.lod_update()
func travel(direction:Vector3):
var heading = _traveler.global_transform.basis
heading = Basis(Vector3.UP*heading.get_euler().y)
direction = -direction
direction = heading * direction
direction = direction.normalized()
$"Chunks".add_central_force(direction*acceleration)
func _physics_process(_state):
ChunkLoader.chunk_update()
var stick = Input.get_axis("ship_down","ship_up")
if stick != 0.0:
self.travel(Vector3.FORWARD*stick)
func free_chunk(chunk):
var coords = chunk.transform.origin
coords = Vector2(coords.x,coords.z)
coords = coords.snapped(Vector2(chunk_size,chunk_size))
ChunkLoader.free_chunk(coords)
|