Level Setup
Integrated with Trenchbroom
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
extends Camera3D
|
||||
|
||||
signal wall_hit(wall_id, position, cutter)
|
||||
|
||||
func shoot_ray() -> Dictionary:
|
||||
var mouse_position = get_viewport().get_mouse_position()
|
||||
var ray_length = 1000
|
||||
var from = project_ray_origin(mouse_position)
|
||||
var to = from + project_ray_normal(mouse_position) * ray_length
|
||||
var space = get_world_3d().direct_space_state
|
||||
var ray_query = PhysicsRayQueryParameters3D.new()
|
||||
ray_query.from = from
|
||||
ray_query.to = to
|
||||
var raycast_result = space.intersect_ray(ray_query)
|
||||
|
||||
return raycast_result
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("left_click"):
|
||||
var query_result = shoot_ray()
|
||||
if query_result:
|
||||
var cutter: PackedVector2Array = Cutter.circleCutter()
|
||||
wall_hit.emit(query_result["collider_id"], query_result["position"], cutter)
|
||||
@@ -1 +0,0 @@
|
||||
uid://cs057402w7w17
|
||||
@@ -1,103 +0,0 @@
|
||||
extends Node
|
||||
|
||||
@export var outer_polygon: PackedVector2Array
|
||||
@export var inner_polygons: Array[PackedVector2Array]
|
||||
@export var edge_non_fracture: float = 0.1
|
||||
|
||||
@onready var camera: Camera3D = get_node("/root/Node3D/Camera3D")
|
||||
@onready var meshInstance = MeshInstance3D.new()
|
||||
@onready var parentNode = get_node("..")
|
||||
|
||||
var depth: float:
|
||||
set(value):
|
||||
if value > 0:
|
||||
depth = -value
|
||||
depth = value
|
||||
|
||||
var static_body: StaticBody3D
|
||||
|
||||
func _ready() -> void:
|
||||
assert(camera, "camera was not found")
|
||||
assert(len(outer_polygon) > 2, "outer polygon does not meet the required length")
|
||||
|
||||
camera.connect("wall_hit", _handle_hit_signal)
|
||||
|
||||
self.add_child(meshInstance)
|
||||
_draw()
|
||||
|
||||
func _draw():
|
||||
var vector_indexes = GeoPolyTriangulization.triangulate(outer_polygon, inner_polygons)
|
||||
var vectors = []
|
||||
|
||||
vectors.append_array(outer_polygon)
|
||||
for ip in inner_polygons:
|
||||
vectors.append_array(ip)
|
||||
|
||||
var meshGenerator = GeoPolyMesh.new(vector_indexes, vectors)
|
||||
var mesh = meshGenerator.commit_mesh()
|
||||
|
||||
meshInstance.mesh = mesh
|
||||
meshInstance.create_trimesh_collision()
|
||||
static_body = _find_static_body()
|
||||
|
||||
func _re_draw():
|
||||
meshInstance.remove_child(static_body)
|
||||
static_body.queue_free()
|
||||
|
||||
var vector_indexes = GeoPolyTriangulization.triangulate(outer_polygon, inner_polygons)
|
||||
var vectors = []
|
||||
|
||||
vectors.append_array(outer_polygon)
|
||||
for ip in inner_polygons:
|
||||
vectors.append_array(ip)
|
||||
|
||||
var meshGenerator = GeoPolyMesh.new(vector_indexes, vectors)
|
||||
var mesh = meshGenerator.commit_mesh()
|
||||
|
||||
meshInstance.mesh = mesh
|
||||
meshInstance.create_trimesh_collision()
|
||||
static_body = _find_static_body()
|
||||
|
||||
|
||||
func _handle_hit_signal(wall_id: int, position: Vector3, cutter: PackedVector2Array):
|
||||
# validate that the hit was to this wall, if not return
|
||||
if wall_id != static_body.get_instance_id():
|
||||
return
|
||||
|
||||
var hole_position_offset = self.position + position
|
||||
var hole_vector2_offset = Vector2(hole_position_offset.x, hole_position_offset.y)
|
||||
|
||||
# translate the cutter
|
||||
var hole_vectors = Transform2D(0, hole_vector2_offset) * cutter
|
||||
|
||||
_add_hole(hole_vectors)
|
||||
|
||||
_re_draw()
|
||||
|
||||
func _add_hole(new_hole: PackedVector2Array):
|
||||
var values_to_remove = []
|
||||
|
||||
var merged: PackedVector2Array = new_hole
|
||||
for index in range(len(self.inner_polygons)):
|
||||
var result = Geometry2D.merge_polygons(merged, self.inner_polygons[index])
|
||||
|
||||
if len(result) == 1:
|
||||
merged = result[0]
|
||||
values_to_remove.append(self.inner_polygons[index])
|
||||
elif len(result) > 1:
|
||||
# need to check that they have no overlapping area if they do clip
|
||||
var overlap = Geometry2D.intersect_polygons(result[0], result[1])
|
||||
|
||||
if len(overlap) != 0:
|
||||
merged = Geometry2D.clip_polygons(result[0], result[1])[0]
|
||||
values_to_remove.append(self.inner_polygons[index])
|
||||
|
||||
for i in values_to_remove:
|
||||
self.inner_polygons.erase(i)
|
||||
|
||||
inner_polygons.append(merged)
|
||||
|
||||
func _find_static_body():
|
||||
for child in meshInstance.get_children():
|
||||
if child is StaticBody3D:
|
||||
return child
|
||||
@@ -2,7 +2,7 @@ extends Node
|
||||
|
||||
class_name Cutter
|
||||
|
||||
static func circleCutter(num_sides = 10, perimerter_length = 0.5) -> PackedVector2Array:
|
||||
static func circleCutter(num_sides = 8, perimerter_length = 0.1) -> PackedVector2Array:
|
||||
var line_length: float = perimerter_length/num_sides
|
||||
var line_angle: float = 360.0/num_sides
|
||||
var current_angle: float = 0.0
|
||||
@@ -0,0 +1,180 @@
|
||||
@tool
|
||||
class_name DestructableWall extends Node3D
|
||||
|
||||
enum ExtrudeDirection {
|
||||
BACK = 0, # z
|
||||
RIGHT = 1, # x
|
||||
UP = 2 # y
|
||||
}
|
||||
|
||||
@export_category("TrechBroom Generated Values")
|
||||
@export var verts2d: PackedVector2Array
|
||||
@export var meshInstance3d: MeshInstance3D
|
||||
@export var extrusion_direction: ExtrudeDirection
|
||||
@export var depth: float = 0.1
|
||||
@export var depth_position_offset: Vector3 = Vector3.ZERO
|
||||
|
||||
@export var edge_non_fracture: float = 0.1
|
||||
@onready var parentNode = get_node("..")
|
||||
|
||||
var outer_polygon: PackedVector2Array
|
||||
var inner_polygons: Array[PackedVector2Array]
|
||||
|
||||
var static_body: StaticBody3D
|
||||
|
||||
func _func_godot_apply_properties(entity_properties: Dictionary) -> void:
|
||||
meshInstance3d = _find_mesh_body()
|
||||
var verticies = meshInstance3d.mesh.surface_get_arrays(0)[Mesh.ARRAY_VERTEX]
|
||||
|
||||
extrusion_direction = entity_properties["extrude_direction"]
|
||||
|
||||
var depth_min: float
|
||||
var depth_max: float
|
||||
|
||||
var verts_2d: PackedVector2Array = []
|
||||
if extrusion_direction == ExtrudeDirection.BACK:
|
||||
for vert in verticies:
|
||||
verts_2d.append(Vector2(vert.x, vert.y))
|
||||
|
||||
var d = vert.z
|
||||
|
||||
if d > depth_max:
|
||||
depth_max = d
|
||||
elif d < depth_min:
|
||||
depth_min = d
|
||||
depth = -(abs(depth_min) + abs(depth_max))
|
||||
|
||||
depth_position_offset = -(Vector3.BACK * (depth/2))
|
||||
elif extrusion_direction == ExtrudeDirection.RIGHT:
|
||||
for vert in verticies:
|
||||
verts_2d.append(Vector2(vert.z, vert.y))
|
||||
|
||||
var d = vert.x
|
||||
|
||||
if d > depth_max:
|
||||
depth_max = d
|
||||
elif d < depth_min:
|
||||
depth_min = d
|
||||
depth = -(abs(depth_min) + abs(depth_max))
|
||||
|
||||
depth_position_offset = Vector3.RIGHT * (depth/2)
|
||||
elif extrusion_direction == ExtrudeDirection.UP:
|
||||
for vert in verticies:
|
||||
verts_2d.append(Vector2(vert.x, vert.z))
|
||||
|
||||
var d = vert.y
|
||||
|
||||
if d > depth_max:
|
||||
depth_max = d
|
||||
elif d < depth_min:
|
||||
depth_min = d
|
||||
depth = -(abs(depth_min) + abs(depth_max))
|
||||
|
||||
depth_position_offset = (Vector3.UP * (depth/2))
|
||||
|
||||
|
||||
var outer_boudary = Geometry2D.convex_hull(verts_2d)
|
||||
verts2d = outer_boudary
|
||||
|
||||
func _ready() -> void:
|
||||
if Engine.is_editor_hint():
|
||||
return
|
||||
|
||||
outer_polygon = verts2d
|
||||
_draw()
|
||||
|
||||
func _draw():
|
||||
var vector_indexes = GeoPolyTriangulization.triangulate(outer_polygon, inner_polygons)
|
||||
var vectors = []
|
||||
|
||||
vectors.append_array(outer_polygon)
|
||||
for ip in inner_polygons:
|
||||
vectors.append_array(ip)
|
||||
|
||||
var meshGenerator = GeoPolyMesh.new(vector_indexes, vectors, extrusion_direction, depth)
|
||||
var commited_mesh = meshGenerator.commit_mesh(meshInstance3d.get_active_material(0))
|
||||
|
||||
meshInstance3d.mesh = commited_mesh
|
||||
meshInstance3d.position += depth_position_offset
|
||||
meshInstance3d.create_trimesh_collision()
|
||||
static_body = _find_static_body()
|
||||
|
||||
func _re_draw():
|
||||
meshInstance3d.remove_child(static_body)
|
||||
static_body.queue_free()
|
||||
|
||||
var vector_indexes = GeoPolyTriangulization.triangulate(outer_polygon, inner_polygons)
|
||||
var vectors = []
|
||||
|
||||
vectors.append_array(outer_polygon)
|
||||
for ip in inner_polygons:
|
||||
vectors.append_array(ip)
|
||||
|
||||
var meshGenerator = GeoPolyMesh.new(vector_indexes, vectors, extrusion_direction, depth)
|
||||
var commited_mesh = meshGenerator.commit_mesh(meshInstance3d.get_active_material(0))
|
||||
|
||||
meshInstance3d.mesh = commited_mesh
|
||||
meshInstance3d.create_trimesh_collision()
|
||||
static_body = _find_static_body()
|
||||
|
||||
|
||||
func hit(position: Vector3):
|
||||
var cutter = Cutter.circleCutter()
|
||||
var hole_position_offset = meshInstance3d.to_local(position)
|
||||
|
||||
var hole_vector2_offset: Vector2
|
||||
if extrusion_direction == ExtrudeDirection.BACK:
|
||||
hole_vector2_offset = Vector2(hole_position_offset.x, hole_position_offset.y)
|
||||
elif extrusion_direction == ExtrudeDirection.RIGHT:
|
||||
hole_vector2_offset = Vector2(hole_position_offset.z, hole_position_offset.y)
|
||||
elif extrusion_direction == ExtrudeDirection.UP:
|
||||
hole_vector2_offset = Vector2(hole_position_offset.x, hole_position_offset.z)
|
||||
|
||||
# translate the cutter
|
||||
var hole_vectors = Transform2D(0, hole_vector2_offset) * cutter
|
||||
var draw = _add_hole(hole_vectors)
|
||||
|
||||
if draw:
|
||||
_re_draw()
|
||||
|
||||
func _add_hole(new_hole: PackedVector2Array) -> bool:
|
||||
var values_to_remove = []
|
||||
|
||||
# validate that the hole is valid
|
||||
var boundary_polygon = Geometry2D.offset_polygon(outer_polygon, -edge_non_fracture)
|
||||
|
||||
var boundary_hole = Geometry2D.intersect_polygons(new_hole, boundary_polygon[0])
|
||||
if !boundary_hole:
|
||||
return false
|
||||
|
||||
var merged: PackedVector2Array = boundary_hole[0]
|
||||
for index in range(len(self.inner_polygons)):
|
||||
var result = Geometry2D.merge_polygons(merged, self.inner_polygons[index])
|
||||
|
||||
if len(result) == 1:
|
||||
merged = result[0]
|
||||
values_to_remove.append(self.inner_polygons[index])
|
||||
elif len(result) > 1:
|
||||
# need to check that they have no overlapping area if they do clip
|
||||
var overlap = Geometry2D.intersect_polygons(result[0], result[1])
|
||||
|
||||
if len(overlap) != 0:
|
||||
merged = Geometry2D.clip_polygons(result[0], result[1])[0]
|
||||
values_to_remove.append(self.inner_polygons[index])
|
||||
|
||||
for i in values_to_remove:
|
||||
inner_polygons.erase(i)
|
||||
|
||||
inner_polygons.append(merged)
|
||||
|
||||
return true
|
||||
|
||||
func _find_static_body():
|
||||
for child in meshInstance3d.get_children():
|
||||
if child is StaticBody3D:
|
||||
return child
|
||||
|
||||
func _find_mesh_body():
|
||||
for child in self.get_children():
|
||||
if child is MeshInstance3D:
|
||||
return child
|
||||
@@ -5,7 +5,7 @@ class_name GeoPolyMesh
|
||||
var surface_array = []
|
||||
|
||||
var verts = PackedVector3Array()
|
||||
var uvs = PackedVector3Array()
|
||||
var uvs = PackedVector2Array()
|
||||
var normals = PackedVector3Array()
|
||||
var array_mesh = ArrayMesh.new()
|
||||
|
||||
@@ -14,20 +14,35 @@ var _v_points = []
|
||||
|
||||
var edges = {}
|
||||
|
||||
func _init(vector_indexes: PackedInt32Array, vector_points: PackedVector2Array, depth: float = -0.1):
|
||||
var depth_vector: Vector3
|
||||
var extrude_direction: DestructableWall.ExtrudeDirection
|
||||
|
||||
func _init(vector_indexes: PackedInt32Array, vector_points: PackedVector2Array, extrude_direction: DestructableWall.ExtrudeDirection, depth: float = -0.1):
|
||||
assert(len(vector_indexes) % 3 == 0 && len(vector_indexes) != 0, "Number of vertex points is not divisible by 3, invalid triangle verticies")
|
||||
surface_array.resize(Mesh.ARRAY_MAX)
|
||||
|
||||
self._v_indexes = vector_indexes
|
||||
self.extrude_direction = extrude_direction
|
||||
|
||||
if extrude_direction == DestructableWall.ExtrudeDirection.BACK:
|
||||
for point in vector_points:
|
||||
self._v_points.append(Vector3(point.x, point.y, 0))
|
||||
depth_vector = Vector3.BACK * depth
|
||||
elif extrude_direction == DestructableWall.ExtrudeDirection.RIGHT:
|
||||
for point in vector_points:
|
||||
self._v_points.append(Vector3(0, point.y, point.x))
|
||||
depth_vector = -Vector3.RIGHT * depth
|
||||
elif extrude_direction == DestructableWall.ExtrudeDirection.UP:
|
||||
for point in vector_points:
|
||||
self._v_points.append(Vector3(point.x, 0, point.y))
|
||||
depth_vector = Vector3.DOWN * depth
|
||||
|
||||
for point in vector_points:
|
||||
self._v_points.append(Vector3(point.x, point.y, 0))
|
||||
|
||||
self._pre_process_edges()
|
||||
|
||||
self._draw_mesh()
|
||||
self._extrude_mesh(depth)
|
||||
self._draw_sides(depth)
|
||||
self._extrude_mesh()
|
||||
self._draw_sides()
|
||||
|
||||
func calculate_area(mesh_vertices: PackedVector2Array) -> float:
|
||||
var result := 0.0
|
||||
@@ -85,9 +100,16 @@ func get_loops():
|
||||
for loop in loops:
|
||||
var vector2_loop = []
|
||||
for ind in loop:
|
||||
vector2_loop.append(self._v_points[ind])
|
||||
var point = self._v_points[ind]
|
||||
if extrude_direction == DestructableWall.ExtrudeDirection.BACK:
|
||||
vector2_loop.append(Vector2(point.x, point.y))
|
||||
elif extrude_direction == DestructableWall.ExtrudeDirection.RIGHT:
|
||||
vector2_loop.append(Vector2(point.z, point.y))
|
||||
elif extrude_direction == DestructableWall.ExtrudeDirection.UP:
|
||||
vector2_loop.append(Vector2(point.x, point.z))
|
||||
vector2_loops.append(vector2_loop)
|
||||
|
||||
|
||||
var area = []
|
||||
for vector2_loop in vector2_loops:
|
||||
var result = self.calculate_area(vector2_loop)
|
||||
@@ -117,7 +139,6 @@ func get_loops():
|
||||
if a < 0: # all inside loops need to rendered in CCW, if + then it is CW
|
||||
loops[area_index].reverse()
|
||||
|
||||
|
||||
return loops
|
||||
|
||||
func get_outline_edge():
|
||||
@@ -131,7 +152,7 @@ func get_outline_edge():
|
||||
func _calc_triangle_normal(a: Vector3, b: Vector3, c: Vector3):
|
||||
return ((b-a).cross(c-a)).normalized()
|
||||
|
||||
func _draw_sides(depth: float):
|
||||
func _draw_sides():
|
||||
var loops = get_loops()
|
||||
|
||||
for l in loops:
|
||||
@@ -139,14 +160,42 @@ func _draw_sides(depth: float):
|
||||
for outline_vector_ind in range(len(outline_edges_ordered) - 1):
|
||||
var v0 = self._v_points[outline_edges_ordered[outline_vector_ind]]
|
||||
var v1 = self._v_points[outline_edges_ordered[outline_vector_ind + 1]]
|
||||
var v2 = self._v_points[outline_edges_ordered[outline_vector_ind]] + Vector3(0, 0, depth)
|
||||
var v3 = self._v_points[outline_edges_ordered[outline_vector_ind + 1]]+ Vector3(0, 0, depth)
|
||||
var v2 = self._v_points[outline_edges_ordered[outline_vector_ind]] + depth_vector
|
||||
var v3 = self._v_points[outline_edges_ordered[outline_vector_ind + 1]] + depth_vector
|
||||
|
||||
#print("v0: ", v0, " v1: ", v1, " v2: ", v2, " v3: ", v3)
|
||||
|
||||
var n1 = self._calc_triangle_normal(v2, v1, v0)
|
||||
|
||||
self.verts.append_array([v0, v1, v2, v1, v3, v2])
|
||||
_append_uvs4(v0, v1, v2, v3, n1)
|
||||
self.normals.append_array([n1, n1, n1, n1, n1, n1])
|
||||
|
||||
func _append_uvs4(v0: Vector3, v1: Vector3, v2: Vector3, v3: Vector3, normal: Vector3):
|
||||
if normal == Vector3.BACK or normal == Vector3.FORWARD:
|
||||
self.uvs.append_array([Vector2(-v0.x, -v0.y), Vector2(-v1.x, -v1.y), Vector2(-v2.x, -v2.y), Vector2(-v1.x, -v1.y), Vector2(-v3.x, -v3.y), Vector2(-v2.x, -v2.y)])
|
||||
return
|
||||
elif normal == Vector3.RIGHT or normal == Vector3.LEFT:
|
||||
self.uvs.append_array([Vector2(-v0.z, -v0.y), Vector2(-v1.z, -v1.y), Vector2(-v2.z, -v2.y), Vector2(-v1.z, -v1.y), Vector2(-v3.z, -v3.y), Vector2(-v2.z, -v2.y)])
|
||||
return
|
||||
elif normal == Vector3.UP or normal == Vector3.DOWN:
|
||||
self.uvs.append_array([Vector2(-v0.x, -v0.z), Vector2(-v1.x, -v1.z), Vector2(-v2.x, -v2.z), Vector2(-v1.x, -v1.z), Vector2(-v3.x, -v3.z), Vector2(-v2.x, -v2.z)])
|
||||
return
|
||||
|
||||
self.uvs.append_array([Vector2(-v0.x, -v0.y), Vector2(-v1.x, -v1.y), Vector2(-v2.x, -v2.y), Vector2(-v1.x, -v1.y), Vector2(-v3.x, -v3.y), Vector2(-v2.x, -v2.y)])
|
||||
|
||||
func _append_uvs3(v0: Vector3, v1: Vector3, v2: Vector3, normal: Vector3):
|
||||
if normal == Vector3.BACK or normal == Vector3.FORWARD:
|
||||
self.uvs.append_array([Vector2(-v0.x, -v0.y), Vector2(-v1.x, -v1.y), Vector2(-v2.x, -v2.y)])
|
||||
return
|
||||
elif normal == Vector3.RIGHT or normal == Vector3.LEFT:
|
||||
self.uvs.append_array([Vector2(-v0.z, -v0.y), Vector2(-v1.z, -v1.y), Vector2(-v2.z, -v2.y)])
|
||||
return
|
||||
elif normal == Vector3.UP or normal == Vector3.DOWN:
|
||||
self.uvs.append_array([Vector2(-v0.x, -v0.z), Vector2(-v1.x, -v1.z), Vector2(-v2.x, -v2.z)])
|
||||
return
|
||||
|
||||
self.uvs.append_array([Vector2(-v0.x, -v0.y), Vector2(-v1.x, -v1.y), Vector2(-v2.x, -v2.y)])
|
||||
|
||||
# front face
|
||||
func _draw_mesh():
|
||||
var vector3A = self._v_points[self._v_indexes[0]]
|
||||
@@ -155,7 +204,10 @@ func _draw_mesh():
|
||||
|
||||
var normal = self._calc_triangle_normal(vector3C, vector3B, vector3A)
|
||||
|
||||
|
||||
self.verts.append_array([vector3A, vector3B, vector3C])
|
||||
_append_uvs3(vector3A, vector3B, vector3C, normal)
|
||||
|
||||
self.normals.append_array([normal, normal, normal])
|
||||
|
||||
# insert each front face into the mesh "clockwise"
|
||||
@@ -164,38 +216,44 @@ func _draw_mesh():
|
||||
vector3B = self._v_points[self._v_indexes[index+1]]
|
||||
vector3C = self._v_points[self._v_indexes[index+2]]
|
||||
|
||||
|
||||
self.verts.append_array([vector3A, vector3B, vector3C])
|
||||
_append_uvs3(vector3A, vector3B, vector3C, normal)
|
||||
self.normals.append_array([normal, normal, normal])
|
||||
#
|
||||
## back face
|
||||
func _extrude_mesh(depth: float):
|
||||
func _extrude_mesh():
|
||||
var vector3A = self._v_points[self._v_indexes[len(self._v_indexes) - 1]]
|
||||
var vector3B = self._v_points[self._v_indexes[len(self._v_indexes) - 2]]
|
||||
var vector3C = self._v_points[self._v_indexes[len(self._v_indexes) - 3]]
|
||||
|
||||
var normal = self._calc_triangle_normal(vector3C, vector3B, vector3A)
|
||||
vector3A = self._v_points[self._v_indexes[len(self._v_indexes) - 1]] - (normal * Vector3(depth, depth, depth))
|
||||
vector3B = self._v_points[self._v_indexes[len(self._v_indexes) - 2]] - (normal * Vector3(depth, depth, depth))
|
||||
vector3C = self._v_points[self._v_indexes[len(self._v_indexes) - 3]] - (normal * Vector3(depth, depth, depth))
|
||||
vector3A = self._v_points[self._v_indexes[len(self._v_indexes) - 1]] + depth_vector
|
||||
vector3B = self._v_points[self._v_indexes[len(self._v_indexes) - 2]] + depth_vector
|
||||
vector3C = self._v_points[self._v_indexes[len(self._v_indexes) - 3]] + depth_vector
|
||||
|
||||
self.verts.append_array([vector3A, vector3B, vector3C])
|
||||
_append_uvs3(vector3A, vector3B, vector3C, normal)
|
||||
|
||||
self.normals.append_array([normal, normal, normal])
|
||||
|
||||
# insert each back face into the mesh "counter-clockwise" extruded
|
||||
for index in range(len(self._v_indexes) - 4, -1, -3):
|
||||
vector3A = self._v_points[self._v_indexes[index]] - (normal * Vector3(depth, depth, depth))
|
||||
vector3B = self._v_points[self._v_indexes[index-1]] - (normal * Vector3(depth, depth, depth))
|
||||
vector3C = self._v_points[self._v_indexes[index-2]] - (normal * Vector3(depth, depth, depth))
|
||||
vector3A = self._v_points[self._v_indexes[index]] + depth_vector
|
||||
vector3B = self._v_points[self._v_indexes[index-1]] + depth_vector
|
||||
vector3C = self._v_points[self._v_indexes[index-2]] + depth_vector
|
||||
|
||||
self.verts.append_array([vector3A, vector3B, vector3C])
|
||||
_append_uvs3(vector3A, vector3B, vector3C, normal)
|
||||
self.normals.append_array([normal, normal, normal])
|
||||
|
||||
func commit_mesh() -> Mesh:
|
||||
func commit_mesh(mat) -> Mesh:
|
||||
surface_array[Mesh.ARRAY_VERTEX] = verts
|
||||
surface_array[Mesh.ARRAY_NORMAL] = normals
|
||||
#surface_array[Mesh.ARRAY_TEX_UV] = uvs
|
||||
surface_array[Mesh.ARRAY_TEX_UV] = uvs
|
||||
|
||||
#print("VERTS: ", self.verts)
|
||||
array_mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, surface_array)
|
||||
array_mesh.surface_set_material(0, mat)
|
||||
|
||||
return array_mesh
|
||||
27
demo/assets/scripts/environment/moving_platform.gd
Normal file
27
demo/assets/scripts/environment/moving_platform.gd
Normal file
@@ -0,0 +1,27 @@
|
||||
@tool
|
||||
class_name MovingPlatform extends AnimatableBody3D
|
||||
|
||||
@export var move_distance: float = 2.0
|
||||
@export var move_time: float = 2.0
|
||||
@export var move_direction: Vector3 = Vector3(0, 1, 0)
|
||||
|
||||
var start_position: Vector3
|
||||
var end_position: Vector3
|
||||
var platform_tween: Tween
|
||||
|
||||
func _func_godot_apply_properties(entity_properties: Dictionary) -> void:
|
||||
move_direction = entity_properties["move_direction"] as Vector3
|
||||
move_time = entity_properties["move_time"] as float
|
||||
move_distance = entity_properties["move_distance"] as float
|
||||
|
||||
func _ready() -> void:
|
||||
if not Engine.is_editor_hint():
|
||||
start_position = global_position
|
||||
end_position = start_position + (move_direction.normalized() * move_distance)
|
||||
_start_movement()
|
||||
|
||||
func _start_movement():
|
||||
platform_tween = create_tween()
|
||||
platform_tween.set_loops()
|
||||
platform_tween.tween_property(self, "global_position", end_position, move_time)
|
||||
platform_tween.tween_property(self, "global_position", start_position, move_time)
|
||||
1
demo/assets/scripts/environment/moving_platform.gd.uid
Normal file
1
demo/assets/scripts/environment/moving_platform.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://br22sm42ks1m0
|
||||
@@ -56,7 +56,6 @@ func update_camera_rotation(input: Vector2) -> void:
|
||||
|
||||
rotation.z = 0.0
|
||||
|
||||
|
||||
func update_camera_height(delta: float, direction: int) -> void:
|
||||
if position.y >= crouch_offset and position.y <= DEFAULT_HEIGHT:
|
||||
position.y = clampf(position.y + (crouch_speed * direction) * delta, crouch_offset, DEFAULT_HEIGHT)
|
||||
|
||||
@@ -53,6 +53,8 @@ const MAX_SCREEN_SHAKE: float = 0.5
|
||||
func _process(delta: float) -> void:
|
||||
calc_view_offset(delta)
|
||||
|
||||
func get_camera_center():
|
||||
return self.get_viewport().get_size() / 2
|
||||
|
||||
func calc_view_offset(delta: float):
|
||||
assert(player, "player is not attached to camera effects script")
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
class_name PlayerController extends CharacterBody3D
|
||||
|
||||
signal hit_static_body(rid, position)
|
||||
|
||||
@export var debug: bool = false
|
||||
@export_category("References")
|
||||
@export var camera: CameraController
|
||||
@@ -30,6 +32,21 @@ var speed: float = 0.0
|
||||
var current_fall_velocity: float
|
||||
var previous_velocity: Vector3
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("left_click"):
|
||||
var center = camera_effects.get_camera_center()
|
||||
var ray_orgin = camera_effects.project_ray_origin(center)
|
||||
var ray_end = ray_orgin + camera_effects.project_ray_normal(center) * 1000
|
||||
|
||||
var new_intersection = PhysicsRayQueryParameters3D.create(ray_orgin, ray_end)
|
||||
var query = get_world_3d().direct_space_state.intersect_ray(new_intersection)
|
||||
|
||||
if query:
|
||||
var collider = query["collider"]
|
||||
var wall = collider.get_parent().get_parent()
|
||||
if wall and wall is DestructableWall:
|
||||
wall.hit(query["position"])
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
previous_velocity = self.velocity
|
||||
|
||||
@@ -67,28 +84,22 @@ func update_rotation(rotation_input) -> void:
|
||||
func sprint() -> void:
|
||||
sprint_modifier = sprint_speed
|
||||
|
||||
|
||||
|
||||
func walk() -> void:
|
||||
sprint_modifier = 0.0
|
||||
|
||||
|
||||
func stand() -> void:
|
||||
crouch_modifier = 0.0
|
||||
standing_collision.disabled = false
|
||||
crouching_collision.disabled = true
|
||||
|
||||
|
||||
func crouch() -> void:
|
||||
crouch_modifier = crouch_speed
|
||||
standing_collision.disabled = true
|
||||
crouching_collision.disabled = false
|
||||
|
||||
|
||||
func jump() -> void:
|
||||
velocity.y += jump_velocity
|
||||
|
||||
|
||||
func check_fall_speed() -> bool:
|
||||
if current_fall_velocity < fall_velocity_threashold:
|
||||
current_fall_velocity = 0.0
|
||||
|
||||
Reference in New Issue
Block a user