Add Do Otboy Godot apartment time-loop prototype
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
extends CharacterBody3D
|
||||
|
||||
var path: Array[Vector3] = []
|
||||
var active := false
|
||||
var speed := 2.8
|
||||
var visual := Node3D.new()
|
||||
var leg_l: MeshInstance3D
|
||||
var leg_r: MeshInstance3D
|
||||
var arm_l: MeshInstance3D
|
||||
var arm_r: MeshInstance3D
|
||||
var walk_time := 0.0
|
||||
|
||||
func _ready() -> void:
|
||||
collision_layer = 2
|
||||
collision_mask = 1
|
||||
var collision := CollisionShape3D.new()
|
||||
var capsule := CapsuleShape3D.new()
|
||||
capsule.radius = 0.21
|
||||
capsule.height = 1.38
|
||||
collision.shape = capsule
|
||||
collision.position.y = 0.76
|
||||
add_child(collision)
|
||||
add_child(visual)
|
||||
# A recognisable female silhouette, built exclusively from primitives.
|
||||
limb(Vector3(0,0.95,0),Vector3(0.48,0.58,0.30),Color("c39b68"))
|
||||
limb(Vector3(0,0.64,0),Vector3(0.41,0.20,0.28),Color("35494d"))
|
||||
leg_l = limb(Vector3(-0.12,0.33,0),Vector3(0.16,0.55,0.18),Color("344349"))
|
||||
leg_r = limb(Vector3(0.12,0.33,0),Vector3(0.16,0.55,0.18),Color("344349"))
|
||||
arm_l = limb(Vector3(-0.30,0.91,0),Vector3(0.13,0.52,0.16),Color("b98c5b"))
|
||||
arm_r = limb(Vector3(0.30,0.91,0),Vector3(0.13,0.52,0.16),Color("b98c5b"))
|
||||
var head := MeshInstance3D.new()
|
||||
var sphere := SphereMesh.new()
|
||||
sphere.radius = 0.21
|
||||
sphere.height = 0.43
|
||||
head.mesh = sphere
|
||||
var skin := StandardMaterial3D.new()
|
||||
skin.albedo_color = Color("d5b299")
|
||||
head.material_override = skin
|
||||
visual.add_child(head)
|
||||
head.position = Vector3(0,1.45,-0.025)
|
||||
limb(Vector3(0,1.59,0.045),Vector3(0.43,0.18,0.38),Color("433c35"))
|
||||
limb(Vector3(0,1.38,0.17),Vector3(0.35,0.29,0.12),Color("433c35"))
|
||||
limb(Vector3(0,1.15,-0.17),Vector3(0.43,0.13,0.08),Color("808f85"))
|
||||
|
||||
func limb(pos: Vector3, size: Vector3, color: Color) -> MeshInstance3D:
|
||||
var mesh := MeshInstance3D.new()
|
||||
var shape := BoxMesh.new()
|
||||
shape.size = size
|
||||
mesh.mesh = shape
|
||||
var mat := StandardMaterial3D.new()
|
||||
mat.albedo_color = color
|
||||
mat.roughness = 0.95
|
||||
mesh.material_override = mat
|
||||
visual.add_child(mesh)
|
||||
mesh.position = pos
|
||||
return mesh
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if not active:
|
||||
velocity = Vector3.ZERO
|
||||
return
|
||||
var direction := Vector3.ZERO
|
||||
if Input.is_physical_key_pressed(KEY_W) or Input.is_physical_key_pressed(KEY_UP):
|
||||
direction.z -= 1
|
||||
if Input.is_physical_key_pressed(KEY_S) or Input.is_physical_key_pressed(KEY_DOWN):
|
||||
direction.z += 1
|
||||
if Input.is_physical_key_pressed(KEY_A) or Input.is_physical_key_pressed(KEY_LEFT):
|
||||
direction.x -= 1
|
||||
if Input.is_physical_key_pressed(KEY_D) or Input.is_physical_key_pressed(KEY_RIGHT):
|
||||
direction.x += 1
|
||||
if direction.length() > 0:
|
||||
path.clear()
|
||||
direction = direction.normalized()
|
||||
elif not path.is_empty():
|
||||
var offset := path[0]-position
|
||||
offset.y = 0
|
||||
if offset.length() < 0.12:
|
||||
path.pop_front()
|
||||
else:
|
||||
direction = offset.normalized()
|
||||
velocity = direction * speed
|
||||
move_and_slide()
|
||||
position.y = 0.08
|
||||
if direction.length() > 0.05:
|
||||
visual.rotation.y = lerp_angle(visual.rotation.y,atan2(-direction.x,-direction.z),minf(delta*14,1))
|
||||
walk_time += delta*10
|
||||
var swing := sin(walk_time)*0.42 if velocity.length()>0.2 else 0.0
|
||||
leg_l.rotation.x = swing
|
||||
leg_r.rotation.x = -swing
|
||||
arm_l.rotation.x = -swing*0.65
|
||||
arm_r.rotation.x = swing*0.65
|
||||
Reference in New Issue
Block a user