jumping, bumping, dieing
This commit is contained in:
parent
8cdf5fdddf
commit
8dc3d3a5b0
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
.mono
|
.mono
|
||||||
|
.vscode
|
||||||
|
|
||||||
|
17
Main.gd
17
Main.gd
@ -2,13 +2,16 @@ extends Node
|
|||||||
export (PackedScene) var mob_scene
|
export (PackedScene) var mob_scene
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
randomize()
|
randomize()
|
||||||
|
|
||||||
|
func _on_Player_hit():
|
||||||
|
$MobTimer.stop()
|
||||||
|
|
||||||
func _on_MobTimer_timeout():
|
func _on_MobTimer_timeout():
|
||||||
var mob = mob_scene.instance()
|
var mob = mob_scene.instance()
|
||||||
var mob_spawn_location = get_node("SpawnPath/SpawnLocation")
|
var mob_spawn_location = get_node("SpawnPath/SpawnLocation")
|
||||||
mob_spawn_location.unit_offset = randf()
|
mob_spawn_location.unit_offset = randf()
|
||||||
var player_position = $Player.transform.origin
|
var player_position = $Player.transform.origin
|
||||||
|
|
||||||
add_child(mob)
|
add_child(mob)
|
||||||
mob.initialize(mob_spawn_location.translation,player_position)
|
mob.initialize(mob_spawn_location.translation,player_position)
|
||||||
|
@ -27,6 +27,8 @@ mob_scene = ExtResource( 2 )
|
|||||||
|
|
||||||
[node name="Ground" type="StaticBody" parent="."]
|
[node name="Ground" type="StaticBody" parent="."]
|
||||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0 )
|
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"]
|
[node name="CollisionShape" type="CollisionShape" parent="Ground"]
|
||||||
shape = SubResource( 1 )
|
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
|
wait_time = 0.5
|
||||||
autostart = true
|
autostart = true
|
||||||
|
|
||||||
|
[connection signal="hit" from="Player" to="." method="_on_Player_hit"]
|
||||||
[connection signal="timeout" from="MobTimer" to="." method="_on_MobTimer_timeout"]
|
[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
|
var velocity = Vector3.ZERO
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
move_and_slide(velocity)
|
move_and_slide(velocity)
|
||||||
|
|
||||||
func initialize(start_position, player_position):
|
func initialize(start_position, player_position):
|
||||||
translation = start_position
|
translation = start_position
|
||||||
look_at(player_position,Vector3.UP)
|
look_at(player_position,Vector3.UP)
|
||||||
rotate_y(rand_range(-PI/4,PI/4))
|
rotate_y(rand_range(-PI/4,PI/4))
|
||||||
|
|
||||||
var random_speed = rand_range(min_speed,max_speed)
|
var random_speed = rand_range(min_speed,max_speed)
|
||||||
velocity = Vector3.FORWARD * random_speed
|
velocity = Vector3.FORWARD * random_speed
|
||||||
velocity = velocity.rotated(Vector3.UP,rotation.y)
|
velocity = velocity.rotated(Vector3.UP,rotation.y)
|
||||||
|
|
||||||
|
func squash():
|
||||||
|
emit_signal("squashed")
|
||||||
|
queue_free()
|
||||||
func _on_VisibilityNotifier_screen_exited():
|
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]
|
[ext_resource path="res://Mob.gd" type="Script" id=2]
|
||||||
|
|
||||||
[sub_resource type="BoxShape" id=1]
|
[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 )
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
[node name="Pivot" type="Spatial" parent="."]
|
[node name="Pivot" type="Spatial" parent="."]
|
||||||
|
54
Player.gd
54
Player.gd
@ -1,24 +1,46 @@
|
|||||||
extends KinematicBody
|
extends KinematicBody
|
||||||
|
|
||||||
|
signal hit
|
||||||
export var speed = 14
|
export var speed = 14
|
||||||
export var fall_accel = 75
|
export var fall_accel = 75
|
||||||
|
export var jump_impulse = 20
|
||||||
|
export var bounce_impulse = 20
|
||||||
var velocity = Vector3.ZERO
|
var velocity = Vector3.ZERO
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
var direction = Vector3.ZERO
|
var direction = Vector3.ZERO
|
||||||
if Input.is_action_pressed("move_right"):
|
if Input.is_action_pressed("move_right"):
|
||||||
direction.x += 1
|
direction.x += 1
|
||||||
if Input.is_action_pressed("move_left"):
|
if Input.is_action_pressed("move_left"):
|
||||||
direction.x -= 1
|
direction.x -= 1
|
||||||
if Input.is_action_pressed("move_forward"):
|
if Input.is_action_pressed("move_forward"):
|
||||||
direction.z -= 1
|
direction.z -= 1
|
||||||
if Input.is_action_pressed("move_back"):
|
if Input.is_action_pressed("move_back"):
|
||||||
direction.z += 1
|
direction.z += 1
|
||||||
|
if is_on_floor() and Input.is_action_pressed("jump"):
|
||||||
|
velocity.y += jump_impulse
|
||||||
|
|
||||||
if direction != Vector3.ZERO:
|
|
||||||
direction = direction.normalized()
|
if direction != Vector3.ZERO:
|
||||||
$Pivot.look_at(translation+direction,Vector3.UP)
|
direction = direction.normalized()
|
||||||
velocity.x = direction.x * speed
|
$Pivot.look_at(translation+direction,Vector3.UP)
|
||||||
velocity.z = direction.z * speed
|
velocity.x = direction.x * speed
|
||||||
velocity.y -= fall_accel * delta
|
velocity.z = direction.z * speed
|
||||||
velocity = move_and_slide(velocity,Vector3.UP)
|
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://art/player.glb" type="PackedScene" id=1]
|
||||||
[ext_resource path="res://Player.gd" type="Script" id=2]
|
[ext_resource path="res://Player.gd" type="Script" id=2]
|
||||||
|
|
||||||
[sub_resource type="SphereShape" id=1]
|
[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"]
|
[node name="Player" type="KinematicBody"]
|
||||||
|
collision_mask = 6
|
||||||
script = ExtResource( 2 )
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
[node name="Pivot" type="Spatial" parent="."]
|
[node name="Pivot" type="Spatial" parent="."]
|
||||||
@ -14,5 +19,16 @@ script = ExtResource( 2 )
|
|||||||
[node name="Character" parent="Pivot" instance=ExtResource( 1 )]
|
[node name="Character" parent="Pivot" instance=ExtResource( 1 )]
|
||||||
|
|
||||||
[node name="CollisionShape" type="CollisionShape" parent="."]
|
[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 )
|
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]
|
[physics]
|
||||||
|
|
||||||
common/enable_pause_aware_picking=true
|
common/enable_pause_aware_picking=true
|
||||||
|
Loading…
Reference in New Issue
Block a user