jumping, bumping, dieing
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -1,2 +1,3 @@
 | 
			
		||||
.mono
 | 
			
		||||
.vscode
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										17
									
								
								Main.gd
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								Main.gd
									
									
									
									
									
								
							@@ -2,13 +2,16 @@ extends Node
 | 
			
		||||
export (PackedScene) var mob_scene
 | 
			
		||||
 | 
			
		||||
func _ready():
 | 
			
		||||
    randomize()
 | 
			
		||||
	randomize()
 | 
			
		||||
 | 
			
		||||
func _on_Player_hit():
 | 
			
		||||
	$MobTimer.stop()
 | 
			
		||||
 | 
			
		||||
func _on_MobTimer_timeout():
 | 
			
		||||
    var mob = mob_scene.instance()
 | 
			
		||||
    var mob_spawn_location = get_node("SpawnPath/SpawnLocation")
 | 
			
		||||
    mob_spawn_location.unit_offset = randf()
 | 
			
		||||
    var player_position = $Player.transform.origin
 | 
			
		||||
	var mob = mob_scene.instance()
 | 
			
		||||
	var mob_spawn_location = get_node("SpawnPath/SpawnLocation")
 | 
			
		||||
	mob_spawn_location.unit_offset = randf()
 | 
			
		||||
	var player_position = $Player.transform.origin
 | 
			
		||||
 | 
			
		||||
    add_child(mob)
 | 
			
		||||
    mob.initialize(mob_spawn_location.translation,player_position)
 | 
			
		||||
	add_child(mob)
 | 
			
		||||
	mob.initialize(mob_spawn_location.translation,player_position)
 | 
			
		||||
 
 | 
			
		||||
@@ -27,6 +27,8 @@ mob_scene = ExtResource( 2 )
 | 
			
		||||
 | 
			
		||||
[node name="Ground" type="StaticBody" parent="."]
 | 
			
		||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0 )
 | 
			
		||||
collision_layer = 4
 | 
			
		||||
collision_mask = 0
 | 
			
		||||
 | 
			
		||||
[node name="CollisionShape" type="CollisionShape" parent="Ground"]
 | 
			
		||||
shape = SubResource( 1 )
 | 
			
		||||
@@ -80,4 +82,5 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -14.295, 0, -12.6559 )
 | 
			
		||||
wait_time = 0.5
 | 
			
		||||
autostart = true
 | 
			
		||||
 | 
			
		||||
[connection signal="hit" from="Player" to="." method="_on_Player_hit"]
 | 
			
		||||
[connection signal="timeout" from="MobTimer" to="." method="_on_MobTimer_timeout"]
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										19
									
								
								Mob.gd
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								Mob.gd
									
									
									
									
									
								
							@@ -6,16 +6,19 @@ export var max_speed = 18
 | 
			
		||||
var velocity = Vector3.ZERO
 | 
			
		||||
 | 
			
		||||
func _physics_process(delta):
 | 
			
		||||
    move_and_slide(velocity)
 | 
			
		||||
	move_and_slide(velocity)
 | 
			
		||||
 | 
			
		||||
func initialize(start_position, player_position):
 | 
			
		||||
    translation = start_position
 | 
			
		||||
    look_at(player_position,Vector3.UP)
 | 
			
		||||
    rotate_y(rand_range(-PI/4,PI/4))
 | 
			
		||||
	translation = start_position
 | 
			
		||||
	look_at(player_position,Vector3.UP)
 | 
			
		||||
	rotate_y(rand_range(-PI/4,PI/4))
 | 
			
		||||
 | 
			
		||||
    var random_speed = rand_range(min_speed,max_speed)
 | 
			
		||||
    velocity = Vector3.FORWARD * random_speed
 | 
			
		||||
    velocity = velocity.rotated(Vector3.UP,rotation.y)
 | 
			
		||||
	var random_speed = rand_range(min_speed,max_speed)
 | 
			
		||||
	velocity = Vector3.FORWARD * random_speed
 | 
			
		||||
	velocity = velocity.rotated(Vector3.UP,rotation.y)
 | 
			
		||||
 | 
			
		||||
func squash():
 | 
			
		||||
	emit_signal("squashed")
 | 
			
		||||
	queue_free()
 | 
			
		||||
func _on_VisibilityNotifier_screen_exited():
 | 
			
		||||
    queue_free()
 | 
			
		||||
	queue_free()
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										8
									
								
								Mob.tscn
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								Mob.tscn
									
									
									
									
									
								
							@@ -4,9 +4,13 @@
 | 
			
		||||
[ext_resource path="res://Mob.gd" type="Script" id=2]
 | 
			
		||||
 | 
			
		||||
[sub_resource type="BoxShape" id=1]
 | 
			
		||||
extents = Vector3( 0.93419, 0.405612, 0.910644 )
 | 
			
		||||
extents = Vector3( 1.14654, 0.405612, 1.49074 )
 | 
			
		||||
 | 
			
		||||
[node name="Mob" type="KinematicBody"]
 | 
			
		||||
[node name="Mob" type="KinematicBody" groups=[
 | 
			
		||||
"mob",
 | 
			
		||||
]]
 | 
			
		||||
collision_layer = 2
 | 
			
		||||
collision_mask = 4
 | 
			
		||||
script = ExtResource( 2 )
 | 
			
		||||
 | 
			
		||||
[node name="Pivot" type="Spatial" parent="."]
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										54
									
								
								Player.gd
									
									
									
									
									
								
							
							
						
						
									
										54
									
								
								Player.gd
									
									
									
									
									
								
							@@ -1,24 +1,46 @@
 | 
			
		||||
extends KinematicBody
 | 
			
		||||
 | 
			
		||||
signal hit
 | 
			
		||||
export var speed = 14
 | 
			
		||||
export var fall_accel = 75
 | 
			
		||||
export var jump_impulse = 20
 | 
			
		||||
export var bounce_impulse = 20
 | 
			
		||||
var velocity = Vector3.ZERO
 | 
			
		||||
 | 
			
		||||
func _physics_process(delta):
 | 
			
		||||
    var direction = Vector3.ZERO
 | 
			
		||||
    if Input.is_action_pressed("move_right"):
 | 
			
		||||
        direction.x += 1
 | 
			
		||||
    if Input.is_action_pressed("move_left"):
 | 
			
		||||
        direction.x -= 1
 | 
			
		||||
    if Input.is_action_pressed("move_forward"):
 | 
			
		||||
        direction.z -= 1
 | 
			
		||||
    if Input.is_action_pressed("move_back"):
 | 
			
		||||
        direction.z += 1
 | 
			
		||||
	var direction = Vector3.ZERO
 | 
			
		||||
	if Input.is_action_pressed("move_right"):
 | 
			
		||||
		direction.x += 1
 | 
			
		||||
	if Input.is_action_pressed("move_left"):
 | 
			
		||||
		direction.x -= 1
 | 
			
		||||
	if Input.is_action_pressed("move_forward"):
 | 
			
		||||
		direction.z -= 1
 | 
			
		||||
	if Input.is_action_pressed("move_back"):
 | 
			
		||||
		direction.z += 1
 | 
			
		||||
	if is_on_floor() and Input.is_action_pressed("jump"):
 | 
			
		||||
		velocity.y += jump_impulse
 | 
			
		||||
 | 
			
		||||
    if direction != Vector3.ZERO:
 | 
			
		||||
        direction = direction.normalized()
 | 
			
		||||
        $Pivot.look_at(translation+direction,Vector3.UP)
 | 
			
		||||
    velocity.x = direction.x * speed
 | 
			
		||||
    velocity.z = direction.z * speed
 | 
			
		||||
    velocity.y -= fall_accel * delta
 | 
			
		||||
    velocity = move_and_slide(velocity,Vector3.UP)
 | 
			
		||||
	
 | 
			
		||||
	if direction != Vector3.ZERO:
 | 
			
		||||
		direction = direction.normalized()
 | 
			
		||||
		$Pivot.look_at(translation+direction,Vector3.UP)
 | 
			
		||||
	velocity.x = direction.x * speed
 | 
			
		||||
	velocity.z = direction.z * speed
 | 
			
		||||
	velocity.y -= fall_accel * delta
 | 
			
		||||
	velocity = move_and_slide(velocity,Vector3.UP)
 | 
			
		||||
 | 
			
		||||
	for index in range(get_slide_count()):
 | 
			
		||||
		var collision = get_slide_collision(index)
 | 
			
		||||
		if collision.collider.is_in_group("mob"):
 | 
			
		||||
			var mob = collision.collider
 | 
			
		||||
			if Vector3.UP.dot(collision.normal)>0.1:
 | 
			
		||||
				mob.squash()
 | 
			
		||||
				velocity.y = bounce_impulse
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
func _on_MobDetector_body_entered(_body):
 | 
			
		||||
	die()
 | 
			
		||||
 | 
			
		||||
func die():
 | 
			
		||||
	emit_signal("hit")
 | 
			
		||||
	queue_free()
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										22
									
								
								Player.tscn
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								Player.tscn
									
									
									
									
									
								
							@@ -1,12 +1,17 @@
 | 
			
		||||
[gd_scene load_steps=4 format=2]
 | 
			
		||||
[gd_scene load_steps=5 format=2]
 | 
			
		||||
 | 
			
		||||
[ext_resource path="res://art/player.glb" type="PackedScene" id=1]
 | 
			
		||||
[ext_resource path="res://Player.gd" type="Script" id=2]
 | 
			
		||||
 | 
			
		||||
[sub_resource type="SphereShape" id=1]
 | 
			
		||||
radius = 1.09537
 | 
			
		||||
radius = 0.909004
 | 
			
		||||
 | 
			
		||||
[sub_resource type="CylinderShape" id=2]
 | 
			
		||||
radius = 1.21236
 | 
			
		||||
height = 0.357992
 | 
			
		||||
 | 
			
		||||
[node name="Player" type="KinematicBody"]
 | 
			
		||||
collision_mask = 6
 | 
			
		||||
script = ExtResource( 2 )
 | 
			
		||||
 | 
			
		||||
[node name="Pivot" type="Spatial" parent="."]
 | 
			
		||||
@@ -14,5 +19,16 @@ script = ExtResource( 2 )
 | 
			
		||||
[node name="Character" parent="Pivot" instance=ExtResource( 1 )]
 | 
			
		||||
 | 
			
		||||
[node name="CollisionShape" type="CollisionShape" parent="."]
 | 
			
		||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.10691, 0 )
 | 
			
		||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.406538, 0 )
 | 
			
		||||
shape = SubResource( 1 )
 | 
			
		||||
 | 
			
		||||
[node name="MobDetector" type="Area" parent="."]
 | 
			
		||||
monitorable = false
 | 
			
		||||
collision_layer = 0
 | 
			
		||||
collision_mask = 2
 | 
			
		||||
 | 
			
		||||
[node name="CollisionShape" type="CollisionShape" parent="MobDetector"]
 | 
			
		||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.392521, 0 )
 | 
			
		||||
shape = SubResource( 2 )
 | 
			
		||||
 | 
			
		||||
[connection signal="body_entered" from="MobDetector" to="." method="_on_MobDetector_body_entered"]
 | 
			
		||||
 
 | 
			
		||||
@@ -52,6 +52,12 @@ jump={
 | 
			
		||||
 ]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
[layer_names]
 | 
			
		||||
 | 
			
		||||
3d_physics/layer_1="player"
 | 
			
		||||
3d_physics/layer_2="enemies"
 | 
			
		||||
3d_physics/layer_3="world"
 | 
			
		||||
 | 
			
		||||
[physics]
 | 
			
		||||
 | 
			
		||||
common/enable_pause_aware_picking=true
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user