jumping, bumping, dieing
This commit is contained in:
parent
8cdf5fdddf
commit
8dc3d3a5b0
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
.mono
|
||||
.vscode
|
||||
|
||||
|
3
Main.gd
3
Main.gd
@ -4,6 +4,9 @@ export (PackedScene) var mob_scene
|
||||
func _ready():
|
||||
randomize()
|
||||
|
||||
func _on_Player_hit():
|
||||
$MobTimer.stop()
|
||||
|
||||
func _on_MobTimer_timeout():
|
||||
var mob = mob_scene.instance()
|
||||
var mob_spawn_location = get_node("SpawnPath/SpawnLocation")
|
||||
|
@ -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"]
|
||||
|
3
Mob.gd
3
Mob.gd
@ -17,5 +17,8 @@ func initialize(start_position, player_position):
|
||||
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()
|
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="."]
|
||||
|
22
Player.gd
22
Player.gd
@ -1,7 +1,10 @@
|
||||
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):
|
||||
@ -14,6 +17,9 @@ func _physics_process(delta):
|
||||
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()
|
||||
@ -22,3 +28,19 @@ func _physics_process(delta):
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user