浏览代码

More tweaks to the 2.5D demo for Godot 4.x

Aaron Franke 1 年之前
父节点
当前提交
57c1cb9ffa

+ 1 - 1
misc/2.5d/addons/node25d/main_screen/gizmo_25d.gd

@@ -74,7 +74,7 @@ func _process(_delta):
 			spatial_node.transform.origin = (spatial_node.transform.origin * Node25D.SCALE).round() / Node25D.SCALE
 	# Move the gizmo lines appropriately.
 	lines_root.global_position = node_25d.global_position
-	node_25d.property_list_changed_notify()
+	node_25d.notify_property_list_changed()
 
 
 # Initializes after _ready due to the onready vars, called manually in Viewport25D.gd.

+ 3 - 3
misc/2.5d/addons/node25d/main_screen/gizmo_25d.tscn

@@ -1,9 +1,9 @@
-[gd_scene load_steps=2 format=2]
+[gd_scene load_steps=2 format=4 uid="uid://cx4xo5jddm0g"]
 
-[ext_resource path="res://addons/node25d/main_screen/gizmo_25d.gd" type="Script" id=1]
+[ext_resource type="Script" path="res://addons/node25d/main_screen/gizmo_25d.gd" id="1"]
 
 [node name="Gizmo25D" type="Node2D"]
-script = ExtResource( 1 )
+script = ExtResource("1")
 
 [node name="Lines" type="Node2D" parent="."]
 

+ 4 - 1
misc/2.5d/addons/node25d/main_screen/main_screen_25d.tscn

@@ -1,4 +1,4 @@
-[gd_scene load_steps=5 format=3 uid="uid://d3xt5cbt06bfy"]
+[gd_scene load_steps=5 format=4 uid="uid://d3xt5cbt06bfy"]
 
 [ext_resource type="Script" path="res://addons/node25d/main_screen/viewport_25d.gd" id="1"]
 [ext_resource type="ButtonGroup" path="res://addons/node25d/main_screen/view_mode_button_group.tres" id="2"]
@@ -61,10 +61,12 @@ size_flags_horizontal = 3
 alignment = 2
 
 [node name="ZoomOut" type="Button" parent="TopBar/Zoom"]
+custom_minimum_size = Vector2(28, 2.08165e-12)
 layout_mode = 2
 text = "-"
 
 [node name="ZoomPercent" type="Label" parent="TopBar/Zoom"]
+custom_minimum_size = Vector2(80, 2.08165e-12)
 layout_mode = 2
 text = "100%"
 horizontal_alignment = 1
@@ -77,6 +79,7 @@ anchor_right = 1.0
 anchor_bottom = 1.0
 
 [node name="ZoomIn" type="Button" parent="TopBar/Zoom"]
+custom_minimum_size = Vector2(28, 2.08165e-12)
 layout_mode = 2
 text = "+"
 

+ 1 - 1
misc/2.5d/addons/node25d/node_25d.gd

@@ -2,8 +2,8 @@
 # The transformation of its 2D form is controlled by its 3D child.
 @tool
 @icon("res://addons/node25d/icons/node_25d_icon.png")
-extends Node2D
 class_name Node25D
+extends Node2D
 
 
 # SCALE is the number of 2D units in one 3D unit. Ideally, but not necessarily, an integer.

+ 14 - 11
misc/2.5d/addons/node25d/shadow_math_25d.gd

@@ -3,12 +3,10 @@
 # is below the target object in the scene tree (not as a child).
 @tool
 @icon("res://addons/node25d/icons/shadow_math_25d_icon.png")
-extends CharacterBody3D
 class_name ShadowMath25D
+extends ShapeCast3D
 
 
-# The maximum distance below objects that shadows will appear (in 3D units).
-var shadow_length = 1000.0
 var _shadow_root: Node25D
 var _target_math: Node3D
 
@@ -16,8 +14,14 @@ var _target_math: Node3D
 func _ready():
 	_shadow_root = get_parent()
 	var index = _shadow_root.get_index()
-	if (index > 0): # Else, Shadow is not in a valid place.
-		_target_math = _shadow_root.get_parent().get_child(index - 1).get_child(0)
+	if index > 0: # Else, Shadow is not in a valid place.
+		var sibling_25d: Node = _shadow_root.get_parent().get_child(index - 1)
+		if sibling_25d.get_child_count() > 0:
+			var target = sibling_25d.get_child(0)
+			if target is Node3D:
+				_target_math = target
+				return
+	printerr("Shadow is not in the correct place, expected a previous sibling node with a 3D first child.")
 
 
 func _physics_process(_delta):
@@ -25,11 +29,10 @@ func _physics_process(_delta):
 		if _shadow_root != null:
 			_shadow_root.visible = false
 		return # Shadow is not in a valid place or you're viewing the Shadow25D scene.
-
 	position = _target_math.position
-	var k = move_and_collide(Vector3.DOWN * shadow_length)
-	if k == null:
-		_shadow_root.visible = false
-	else:
+	force_shapecast_update()
+	if is_colliding():
+		global_position = get_collision_point(0)
 		_shadow_root.visible = true
-		global_transform = transform
+	else:
+		_shadow_root.visible = false

+ 2 - 2
misc/2.5d/assets/cube/cube_math.gd

@@ -11,9 +11,9 @@ func _ready():
 	_parent = get_parent()
 
 	for i in range(27):
-		# warning-ignore:integer_division
+		@warning_ignore("integer_division")
 		var a: int = (i / 9) - 1
-		# warning-ignore:integer_division
+		@warning_ignore("integer_division")
 		var b: int = (i / 3) % 3 - 1
 		var c: int = (i % 3) - 1
 		var spatial_position: Vector3 = 5 * (a * Vector3.RIGHT + b * Vector3.UP + c * Vector3.BACK)

+ 6 - 7
misc/2.5d/assets/demo_scene.tscn

@@ -1,4 +1,4 @@
-[gd_scene load_steps=12 format=3 uid="uid://bc8akj25hcmiy"]
+[gd_scene load_steps=12 format=4 uid="uid://bc8akj25hcmiy"]
 
 [ext_resource type="PackedScene" uid="uid://6o8sm5bti8d1" path="res://assets/ui/overlay.tscn" id="1"]
 [ext_resource type="PackedScene" uid="uid://bg27d8sfehmr4" path="res://assets/player/player_25d.tscn" id="2"]
@@ -23,17 +23,16 @@ size = Vector3(10, 1, 10)
 [node name="Overlay" parent="." instance=ExtResource("1")]
 
 [node name="Player25D" parent="." instance=ExtResource("2")]
-z_index = -3952
-position = Vector2(0, -226.274)
+z_index = -3956
 
 [node name="Shadow25D" parent="." instance=ExtResource("3")]
 visible = true
 z_index = -3958
-position = Vector2(0, -5.3033)
-spatial_position = Vector3(0, 0.234375, 0)
+position = Vector2(0, 10.7834)
+spatial_position = Vector3(0, -0.476562, 0)
 
 [node name="Platform0" type="Node2D" parent="."]
-z_index = -3954
+z_index = -3952
 position = Vector2(-256, -113.137)
 script = ExtResource("4")
 spatial_position = Vector3(-8, 5, 0)
@@ -52,7 +51,7 @@ texture = ExtResource("6")
 script = ExtResource("7")
 
 [node name="Platform1" type="Node2D" parent="."]
-z_index = -3956
+z_index = -3954
 position = Vector2(-256, -339.411)
 script = ExtResource("4")
 spatial_position = Vector3(-8, 5, -10)

+ 3 - 4
misc/2.5d/assets/player/player_25d.tscn

@@ -1,12 +1,11 @@
-[gd_scene load_steps=6 format=3 uid="uid://bg27d8sfehmr4"]
+[gd_scene load_steps=6 format=4 uid="uid://bg27d8sfehmr4"]
 
 [ext_resource type="Script" path="res://addons/node25d/node_25d.gd" id="1"]
 [ext_resource type="Script" path="res://assets/player/player_math_25d.gd" id="3"]
 [ext_resource type="Texture2D" uid="uid://bfdfertqyhf1u" path="res://assets/player/textures/jump.png" id="4"]
 [ext_resource type="Script" path="res://assets/player/player_sprite.gd" id="5"]
 
-[sub_resource type="BoxShape3D" id="1"]
-size = Vector3(1, 2, 1)
+[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_b17hs"]
 
 [node name="Player25D" type="Node2D"]
 z_index = 100
@@ -19,7 +18,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
 script = ExtResource("3")
 
 [node name="CollisionShape3D" type="CollisionShape3D" parent="PlayerMath25D"]
-shape = SubResource("1")
+shape = SubResource("CapsuleShape3D_b17hs")
 
 [node name="PlayerSprite" type="Sprite2D" parent="."]
 z_index = 1

+ 5 - 6
misc/2.5d/assets/player/player_math_25d.gd

@@ -1,6 +1,6 @@
 # Handles Player-specific behavior like moving. We calculate such things with CharacterBody3D.
-extends CharacterBody3D
 class_name PlayerMath25D # No icon necessary
+extends CharacterBody3D
 
 var vertical_speed := 0.0
 var isometric_controls := true
@@ -38,7 +38,7 @@ func _horizontal_movement(delta):
 	var movement_vec2 = Input.get_vector(&"move_left", &"move_right", &"move_forward", &"move_back")
 	var move_dir = localX * movement_vec2.x + localZ * movement_vec2.y
 
-	velocity = move_dir * delta * 1200
+	velocity = move_dir * 10
 	if Input.is_action_pressed(&"movement_modifier"):
 		velocity /= 2
 
@@ -47,10 +47,9 @@ func _horizontal_movement(delta):
 
 # Checks Jump and applies gravity and vertical speed via move_and_collide.
 func _vertical_movement(delta):
-	var localY = Vector3.UP
 	if Input.is_action_just_pressed(&"jump"):
-		vertical_speed = 0.55
-	vertical_speed -= delta * 2 # Gravity
-	var k = move_and_collide(localY * vertical_speed)
+		vertical_speed = 60
+	vertical_speed -= delta * 240 # Gravity
+	var k = move_and_collide(Vector3.UP * vertical_speed * delta)
 	if k != null:
 		vertical_speed = 0

+ 1 - 1
misc/2.5d/assets/player/player_sprite.gd

@@ -30,7 +30,7 @@ func _process(delta):
 		if movement:
 			hframes = 6
 			texture = _run
-			if (Input.is_action_pressed(&"movement_modifier")):
+			if Input.is_action_pressed(&"movement_modifier"):
 				delta /= 2
 			_progress = fmod((_progress + FRAMERATE * delta), 6)
 			frame = _direction * 6 + int(_progress)

+ 5 - 12
misc/2.5d/assets/shadow/shadow_25d.tscn

@@ -1,13 +1,11 @@
-[gd_scene load_steps=7 format=3 uid="uid://ivolxaqaaddk"]
+[gd_scene load_steps=6 format=4 uid="uid://ivolxaqaaddk"]
 
 [ext_resource type="Script" path="res://addons/node25d/node_25d.gd" id="1"]
 [ext_resource type="Script" path="res://addons/node25d/shadow_math_25d.gd" id="3"]
-[ext_resource type="Texture2D" uid="uid://dunp4dxxpftxb" path="res://addons/node25d/icons/shadow_math_25d_icon.png" id="4"]
 [ext_resource type="Texture2D" uid="uid://4fvxohv2aowy" path="res://assets/shadow/textures/forty_five.png" id="5"]
 [ext_resource type="Script" path="res://assets/shadow/shadow_sprite.gd" id="6"]
 
-[sub_resource type="BoxShape3D" id="1"]
-size = Vector3(1, 0.002, 1)
+[sub_resource type="SphereShape3D" id="SphereShape3D_v7tld"]
 
 [node name="Shadow25D" type="Node2D"]
 visible = false
@@ -15,17 +13,12 @@ position = Vector2(0, 22401.1)
 script = ExtResource("1")
 spatial_position = Vector3(0, -990, 0)
 
-[node name="ShadowMath25D" type="CharacterBody3D" parent="."]
+[node name="ShadowMath25D" type="ShapeCast3D" parent="."]
 transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -990, 0)
-collision_layer = 16
+shape = SubResource("SphereShape3D_v7tld")
+target_position = Vector3(2.08165e-12, -100, 2.08165e-12)
 collision_mask = 16
 script = ExtResource("3")
-__meta__ = {
-"_editor_icon": ExtResource("4")
-}
-
-[node name="CollisionShape3D" type="CollisionShape3D" parent="ShadowMath25D"]
-shape = SubResource("1")
 
 [node name="ShadowSprite" type="Sprite2D" parent="."]
 texture_filter = 2

+ 1 - 1
misc/2.5d/assets/ui/overlay.tscn

@@ -1,4 +1,4 @@
-[gd_scene load_steps=2 format=3 uid="uid://6o8sm5bti8d1"]
+[gd_scene load_steps=2 format=4 uid="uid://6o8sm5bti8d1"]
 
 [ext_resource type="Script" path="res://assets/ui/control_hints.gd" id="1"]