Lots of memes

Added commentary cube thing
Added interactions
Camera no longer dogshit
Added noclip
Added "run"
Updated to new assets ref
Added mouse capture / "pause"
This commit is contained in:
Thomas Muller 2023-09-27 21:55:59 -04:00
parent ced46f48a9
commit d4becae392
7 changed files with 200 additions and 46 deletions

36
Commentary.gd Normal file
View file

@ -0,0 +1,36 @@
extends Node3D
@export
var capture_radius = 10.0
@export
var low_speed = 1.0
@export
var high_speed = 10.0
@export
var pre = 1.0
@export
var post = 1.0
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
var players = get_tree().get_nodes_in_group("Players")
var shortest_distance = capture_radius
for player in players:
var player_dist = self.position.distance_to(player.position)
shortest_distance = min(shortest_distance, player_dist)
var weight = (capture_radius - shortest_distance) / capture_radius
var spin_speed = cubic_interpolate(low_speed, high_speed, pre, post, weight)
self.rotate_y(spin_speed * delta)
func interact(other):
var random_color = Color(randf(), randf(), randf())
$Koob.material.albedo_color = random_color
print(other)

53
Commentary.tscn Normal file
View file

@ -0,0 +1,53 @@
[gd_scene load_steps=8 format=3 uid="uid://wl1n3y8mcq0x"]
[ext_resource type="Script" path="res://Commentary.gd" id="1_omu2m"]
[sub_resource type="BoxMesh" id="BoxMesh_sbsxh"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_7hakv"]
albedo_color = Color(0, 1, 1, 1)
[sub_resource type="Animation" id="Animation_njjyi"]
resource_name = "bob"
length = 2.0
loop_mode = 1
tracks/0/type = "position_3d"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".")
tracks/0/interp = 2
tracks/0/loop_wrap = true
tracks/0/keys = PackedFloat32Array(0, 1, 0, 0.75, 0, 1, 1, 0, 1.25, 0, 2, 1, 0, 0.75, 0)
[sub_resource type="AnimationLibrary" id="AnimationLibrary_xohyp"]
_data = {
"bob": SubResource("Animation_njjyi")
}
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_lh675"]
animation = &"bob"
[sub_resource type="BoxShape3D" id="BoxShape3D_k4wkk"]
size = Vector3(1, 1.5, 1)
[node name="Commentary" type="StaticBody3D"]
script = ExtResource("1_omu2m")
[node name="Koob" type="CSGMesh3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.11043, 0)
mesh = SubResource("BoxMesh_sbsxh")
material = SubResource("StandardMaterial3D_7hakv")
[node name="AnimationPlayer" type="AnimationPlayer" parent="Koob"]
libraries = {
"": SubResource("AnimationLibrary_xohyp")
}
[node name="AnimationTree" type="AnimationTree" parent="Koob"]
tree_root = SubResource("AnimationNodeAnimation_lh675")
anim_player = NodePath("../AnimationPlayer")
active = true
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
shape = SubResource("BoxShape3D_k4wkk")

102
Player.gd
View file

@ -5,7 +5,7 @@ var walk_speed = 1.0
var g = -9.8 var g = -9.8
const MAX_SPEED = 5 const MAX_SPEED = 5
const JUMP_SPEED = 7 const JUMP_SPEED = 5
const ACCEL= 8 const ACCEL= 8
const DEACCEL= 8 const DEACCEL= 8
const MAX_SLOPE_ANGLE = 30 const MAX_SLOPE_ANGLE = 30
@ -13,67 +13,91 @@ const MAX_SLOPE_ANGLE = 30
@onready @onready
var camera = $CSGMesh3D/Camera3D var camera = $CSGMesh3D/Camera3D
var _paused = false
var _noclip = false
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _physics_process(delta): func _physics_process(delta):
var dir = Vector3() # Where does the player intend to walk to var move_dir = Vector3() # Where does the player intend to walk to
var cam_xform = camera.get_global_transform() var cam_xform = camera.get_global_transform()
if Input.is_action_pressed("move_forward"): if Input.is_action_pressed("move_forward"):
dir += -cam_xform.basis[2] move_dir += -cam_xform.basis.z
if Input.is_action_pressed("move_backwards"): if Input.is_action_pressed("move_backwards"):
dir += cam_xform.basis[2] move_dir += cam_xform.basis.z
if Input.is_action_pressed("move_left"): if Input.is_action_pressed("move_left"):
dir += -cam_xform.basis[0] move_dir += -cam_xform.basis.x
if Input.is_action_pressed("move_right"): if Input.is_action_pressed("move_right"):
dir += cam_xform.basis[0] move_dir += cam_xform.basis.x
dir.y = 0 if not _noclip:
dir = dir.normalized() move_dir.y = 0
move_dir = move_dir.normalized()
velocity.y += delta * g var target = move_dir * MAX_SPEED
if Input.is_action_pressed("run"):
var hvel = velocity target *= 5
hvel.y = 0
var target = dir * MAX_SPEED
var accel var accel
if dir.dot(hvel) > 0: if move_dir.dot(target) > 0:
accel = ACCEL accel = ACCEL
else: else:
accel = DEACCEL accel = DEACCEL
hvel = hvel.lerp(target, accel * delta) var new_vel = velocity.lerp(target, accel * delta)
velocity.x = new_vel.x
velocity.z = new_vel.z
if _noclip:
velocity.y = new_vel.y
velocity.x = hvel.x if not _noclip:
velocity.z = hvel.z velocity.y += g * delta
if is_on_floor() and Input.is_action_pressed("jump"):
velocity.y += JUMP_SPEED
move_and_slide() move_and_slide()
$Ball.global_position = camera.global_position - camera.global_transform.basis.z * 5.0
if is_on_floor() and Input.is_action_pressed("jump"):
velocity.y = JUMP_SPEED
func _on_tcube_body_enter(body):
if body == self:
get_node("../ty").show()
# accumulators
var rot_x = 0
var rot_y = 0
func _input(event): func _input(event):
if event is InputEventMouseMotion and event.button_mask & 2: if event.is_action_pressed("pause"):
# modify accumulated mouse rotation _paused = not _paused
rot_x -= event.relative.x * 0.005 if _paused:
rot_y -= event.relative.y * 0.005 Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
camera.transform.basis = Basis() # reset rotation else:
camera.rotate_object_local(Vector3(0, 1, 0), rot_x) # first rotate in Y Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
camera.rotate_object_local(Vector3(1, 0, 0), rot_y) # then rotate in X
if _paused: return
if event.is_action_pressed('noclip'):
_noclip = not _noclip
if _noclip:
$CollisionShape3D.disabled = true
else:
$CollisionShape3D.disabled = false
# Check for mouse motion input
if event is InputEventMouseMotion:
rotation.y += -event.relative.x * 0.005
camera.rotation.x += -event.relative.y * 0.005
camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(-70), deg_to_rad(70))
if event.is_action_pressed("interact"): if event.is_action_pressed("interact"):
var space_state = get_world_3d().direct_space_state var space_state = get_world_3d().direct_space_state
# use global coordinates, not local to node # use global coordinates, not local to node
print(camera.basis) var query = PhysicsRayQueryParameters3D.create(camera.global_position, $Ball.global_position)
var query = PhysicsRayQueryParameters3D.create(camera.position, camera.position + camera.basis.z * 2.0) # Don't collide with ourselves
query.exclude = [self]
var result = space_state.intersect_ray(query) var result = space_state.intersect_ray(query)
print(result) if result.has('collider'):
var other: Node3D = result.collider
if other.has_method('interact'):
other.interact(self)

View file

@ -6,7 +6,7 @@
[sub_resource type="CapsuleMesh" id="CapsuleMesh_hkqbf"] [sub_resource type="CapsuleMesh" id="CapsuleMesh_hkqbf"]
[node name="Player" type="CharacterBody3D"] [node name="Player" type="CharacterBody3D" groups=["Players"]]
script = ExtResource("1_0rkr0") script = ExtResource("1_0rkr0")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."] [node name="CollisionShape3D" type="CollisionShape3D" parent="."]
@ -19,3 +19,8 @@ mesh = SubResource("CapsuleMesh_hkqbf")
[node name="Camera3D" type="Camera3D" parent="CSGMesh3D"] [node name="Camera3D" type="Camera3D" parent="CSGMesh3D"]
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)
current = true
size = 6.683
[node name="Ball" type="CSGSphere3D" parent="."]
radius = 0.2

2
assets

@ -1 +1 @@
Subproject commit 8ecf8f1da3a244b134b8d2d324479c07da8b859f Subproject commit 38571edc27c25ccaf1523c28f54b4fa096275b53

View file

@ -47,3 +47,18 @@ interact={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"key_label":0,"unicode":101,"echo":false,"script":null) "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"key_label":0,"unicode":101,"echo":false,"script":null)
] ]
} }
run={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194325,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}
pause={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194305,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}
noclip={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":86,"key_label":0,"unicode":118,"echo":false,"script":null)
]
}

File diff suppressed because one or more lines are too long