Rearranging files, adding block type, converted movement to camera based, added jump
This commit is contained in:
parent
0e30adabc3
commit
5893123adb
@ -1,6 +1,7 @@
|
|||||||
[gd_scene load_steps=9 format=3 uid="uid://dchj6g2i8ebph"]
|
[gd_scene load_steps=10 format=3 uid="uid://dchj6g2i8ebph"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://bpxggc8nr6tf6" path="res://scenes/player.gd" id="2_w7c3h"]
|
[ext_resource type="Script" uid="uid://bpxggc8nr6tf6" path="res://scenes/player.gd" id="1_muv8p"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://c5of6aaxop1hl" path="res://scenes/block.tscn" id="2_tc7dm"]
|
||||||
|
|
||||||
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_2q6dc"]
|
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_2q6dc"]
|
||||||
bounce = 0.5
|
bounce = 0.5
|
||||||
@ -39,14 +40,14 @@ mesh = SubResource("SphereMesh_w7c3h")
|
|||||||
|
|
||||||
[node name="Player" type="RigidBody3D" parent="."]
|
[node name="Player" type="RigidBody3D" parent="."]
|
||||||
physics_material_override = SubResource("PhysicsMaterial_w8frs")
|
physics_material_override = SubResource("PhysicsMaterial_w8frs")
|
||||||
gravity_scale = 0.0
|
script = ExtResource("1_muv8p")
|
||||||
script = ExtResource("2_w7c3h")
|
camera_path = NodePath("Camera3D")
|
||||||
|
|
||||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Player"]
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="Player"]
|
||||||
shape = SubResource("SphereShape3D_mx8sn")
|
shape = SubResource("SphereShape3D_mx8sn")
|
||||||
|
|
||||||
[node name="Camera3D" type="Camera3D" parent="Player"]
|
[node name="Camera3D" type="Camera3D" parent="Player"]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.31670225, 0)
|
||||||
|
|
||||||
[node name="Ground" type="StaticBody3D" parent="."]
|
[node name="Ground" type="StaticBody3D" parent="."]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0)
|
||||||
@ -60,3 +61,11 @@ mesh = SubResource("BoxMesh_w7c3h")
|
|||||||
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
|
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
|
||||||
transform = Transform3D(1, 0, 0, 0, 0.5, 0.8660253, 0, -0.8660253, 0.5, 0, 34, 0)
|
transform = Transform3D(1, 0, 0, 0, 0.5, 0.8660253, 0, -0.8660253, 0.5, 0, 34, 0)
|
||||||
shadow_enabled = true
|
shadow_enabled = true
|
||||||
|
|
||||||
|
[node name="Starter Blocks" type="Node3D" parent="."]
|
||||||
|
|
||||||
|
[node name="Block" parent="Starter Blocks" instance=ExtResource("2_tc7dm")]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.298158, -7.0724635)
|
||||||
|
|
||||||
|
[node name="Block2" parent="Starter Blocks" instance=ExtResource("2_tc7dm")]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.63255787, 2.596316, -6.980046)
|
||||||
@ -2,4 +2,4 @@ extends Node
|
|||||||
|
|
||||||
func _input(event):
|
func _input(event):
|
||||||
if event.is_action_pressed("ui_cancel"): # 'ui_cancel' is a built-in action defined in Project > Project Settings > Input Map
|
if event.is_action_pressed("ui_cancel"): # 'ui_cancel' is a built-in action defined in Project > Project Settings > Input Map
|
||||||
get_tree().change_scene_to_file("res://scenes/start_screen.tscn")
|
get_tree().change_scene_to_file("uid://b4k81taauef4q")
|
||||||
@ -1,10 +1,11 @@
|
|||||||
[gd_scene load_steps=5 format=3 uid="uid://d3tqrm4ry4l88"]
|
[gd_scene load_steps=5 format=3 uid="uid://d3tqrm4ry4l88"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://h1slqbemgwvr" path="res://scenes/Settings.gd" id="1_1dggd"]
|
[ext_resource type="Script" uid="uid://h1slqbemgwvr" path="res://scenes/UI/Settings.gd" id="1_1dggd"]
|
||||||
[ext_resource type="Texture2D" uid="uid://dhuosr0p605gj" path="res://assets/images/pp_start_bg.png" id="1_i47rn"]
|
[ext_resource type="Texture2D" uid="uid://dhuosr0p605gj" path="res://assets/images/pp_start_bg.png" id="1_i47rn"]
|
||||||
[ext_resource type="FontFile" uid="uid://m5ceou0rk6j6" path="res://assets/fonts/PlayfairDisplay-VariableFont_wght.ttf" id="2_46duy"]
|
[ext_resource type="FontFile" uid="uid://m5ceou0rk6j6" path="res://assets/fonts/PlayfairDisplay-VariableFont_wght.ttf" id="2_46duy"]
|
||||||
[ext_resource type="Theme" uid="uid://wpxmub0n2dr3" path="res://themes/button_theme.tres" id="3_46duy"]
|
[ext_resource type="Theme" uid="uid://wpxmub0n2dr3" path="res://themes/button_theme.tres" id="3_46duy"]
|
||||||
|
|
||||||
|
|
||||||
[node name="settings_screen" type="Node2D"]
|
[node name="settings_screen" type="Node2D"]
|
||||||
script = ExtResource("1_1dggd")
|
script = ExtResource("1_1dggd")
|
||||||
metadata/_edit_vertical_guides_ = [1152.0]
|
metadata/_edit_vertical_guides_ = [1152.0]
|
||||||
@ -2,10 +2,10 @@ extends Control
|
|||||||
|
|
||||||
|
|
||||||
func _on_start_button_pressed():
|
func _on_start_button_pressed():
|
||||||
get_tree().change_scene_to_file("res://scenes/level.tscn")
|
get_tree().change_scene_to_file("uid://dchj6g2i8ebph")
|
||||||
|
|
||||||
func _on_settings_button_pressed():
|
func _on_settings_button_pressed():
|
||||||
get_tree().change_scene_to_file("res://scenes/Settings.tscn")
|
get_tree().change_scene_to_file("uid://d3tqrm4ry4l88")
|
||||||
|
|
||||||
func _on_quit_button_pressed():
|
func _on_quit_button_pressed():
|
||||||
get_tree().quit()
|
get_tree().quit()
|
||||||
@ -1,6 +1,6 @@
|
|||||||
[gd_scene load_steps=5 format=3 uid="uid://b4k81taauef4q"]
|
[gd_scene load_steps=5 format=3 uid="uid://b4k81taauef4q"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://cc8lskf7y74kh" path="res://scenes/start_screen.gd" id="1_o7i0r"]
|
[ext_resource type="Script" uid="uid://cc8lskf7y74kh" path="res://scenes/UI/start_screen.gd" id="1_o7i0r"]
|
||||||
[ext_resource type="Theme" uid="uid://wpxmub0n2dr3" path="res://themes/button_theme.tres" id="1_tx5wa"]
|
[ext_resource type="Theme" uid="uid://wpxmub0n2dr3" path="res://themes/button_theme.tres" id="1_tx5wa"]
|
||||||
[ext_resource type="Texture2D" uid="uid://dhuosr0p605gj" path="res://assets/images/pp_start_bg.png" id="2_r2jwc"]
|
[ext_resource type="Texture2D" uid="uid://dhuosr0p605gj" path="res://assets/images/pp_start_bg.png" id="2_r2jwc"]
|
||||||
[ext_resource type="Theme" uid="uid://tn8qndst18d6" path="res://themes/title_font_theme.tres" id="4_hm208"]
|
[ext_resource type="Theme" uid="uid://tn8qndst18d6" path="res://themes/title_font_theme.tres" id="4_hm208"]
|
||||||
21
scenes/block.tscn
Normal file
21
scenes/block.tscn
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
[gd_scene load_steps=4 format=3 uid="uid://c5of6aaxop1hl"]
|
||||||
|
|
||||||
|
[sub_resource type="BoxShape3D" id="BoxShape3D_4du60"]
|
||||||
|
|
||||||
|
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_alp5v"]
|
||||||
|
albedo_color = Color(0.290196, 0.698039, 0.227451, 1)
|
||||||
|
|
||||||
|
[sub_resource type="BoxMesh" id="BoxMesh_kryjk"]
|
||||||
|
material = SubResource("StandardMaterial3D_alp5v")
|
||||||
|
|
||||||
|
[node name="Block" type="Node3D"]
|
||||||
|
|
||||||
|
[node name="RigidBody3D" type="RigidBody3D" parent="."]
|
||||||
|
collision_layer = 3
|
||||||
|
collision_mask = 3
|
||||||
|
|
||||||
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="RigidBody3D"]
|
||||||
|
shape = SubResource("BoxShape3D_4du60")
|
||||||
|
|
||||||
|
[node name="MeshInstance3D" type="MeshInstance3D" parent="RigidBody3D"]
|
||||||
|
mesh = SubResource("BoxMesh_kryjk")
|
||||||
@ -1,16 +1,52 @@
|
|||||||
extends RigidBody3D
|
extends RigidBody3D
|
||||||
|
|
||||||
# Initially I used a CharacterBody3D, however, I wanted the player to bounce off
|
const MOVE_SPEED := 8.0
|
||||||
# other objects in the environment and that would have required manual handling
|
const ACCELLERATION := 30.0
|
||||||
# of collisions. So that's why we're using a RigidBody3D instead.
|
const DECELLERATION := 40.0
|
||||||
|
const JUMP_SPEED := 4.0
|
||||||
|
|
||||||
const ACCELLERATION = 5.0
|
@export var camera_path: NodePath
|
||||||
|
@onready var cam: Camera3D = get_node(camera_path) if camera_path != NodePath("") else null
|
||||||
|
|
||||||
func _integrate_forces(state):
|
func _ready() -> void:
|
||||||
var input_dir = Vector3.ZERO
|
axis_lock_angular_x = true
|
||||||
input_dir.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
|
axis_lock_angular_z = true
|
||||||
input_dir.z = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
|
angular_damp = 6.0
|
||||||
input_dir = input_dir.normalized()
|
contact_monitor = true
|
||||||
|
max_contacts_reported = 4
|
||||||
|
|
||||||
linear_velocity.x += input_dir.x * (ACCELLERATION * state.step)
|
func _integrate_forces(state):
|
||||||
linear_velocity.z += input_dir.z * (ACCELLERATION * state.step)
|
# Input as 2D vector
|
||||||
|
var input2v := Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
|
||||||
|
|
||||||
|
# Camera based movement
|
||||||
|
var forward := Vector3.FORWARD * -1.0
|
||||||
|
var right := Vector3.RIGHT
|
||||||
|
if cam:
|
||||||
|
forward = cam.global_transform.basis.z
|
||||||
|
right = cam.global_transform.basis.x
|
||||||
|
# project onto ground plane so looking up/down doesn't tilt movement
|
||||||
|
forward.y = 0.0
|
||||||
|
right.y = 0.0
|
||||||
|
if forward.length() > 0.0001:
|
||||||
|
forward = forward.normalized()
|
||||||
|
if right.length() > 0.0001:
|
||||||
|
right = right.normalized()
|
||||||
|
|
||||||
|
var dir := (right * input2v.x + forward * input2v.y).normalized()
|
||||||
|
var target_v := dir * MOVE_SPEED
|
||||||
|
|
||||||
|
var ax := ACCELLERATION if dir != Vector3.ZERO else DECELLERATION
|
||||||
|
linear_velocity.x = move_toward(linear_velocity.x, target_v.x, ax * state.step)
|
||||||
|
linear_velocity.z = move_toward(linear_velocity.z, target_v.z, ax * state.step)
|
||||||
|
|
||||||
|
# Jump Logic
|
||||||
|
var on_floor = false
|
||||||
|
for i in state.get_contact_count():
|
||||||
|
var normal = state.get_contact_local_normal(i)
|
||||||
|
if normal.y > 0.5:
|
||||||
|
on_floor = true
|
||||||
|
break
|
||||||
|
|
||||||
|
if on_floor and Input.is_action_just_pressed("ui_accept"):
|
||||||
|
linear_velocity.y = JUMP_SPEED
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user