From eb2cd95a09267721f29ad651565e5b65b6fdee41 Mon Sep 17 00:00:00 2001 From: karl Date: Sat, 23 Nov 2019 22:47:36 +0100 Subject: [PATCH] Improve collision, use more Areas instead of bodys --- WikiJam/Enemies/Dino.tscn | 23 ++++++++++++++++------- WikiJam/Level/Objects/Crystal.tscn | 6 +++--- WikiJam/Player/Player.gd | 28 +++++++++++++--------------- WikiJam/Player/Player.tscn | 1 + 4 files changed, 33 insertions(+), 25 deletions(-) diff --git a/WikiJam/Enemies/Dino.tscn b/WikiJam/Enemies/Dino.tscn index cabff79..79d70cd 100644 --- a/WikiJam/Enemies/Dino.tscn +++ b/WikiJam/Enemies/Dino.tscn @@ -1,10 +1,10 @@ -[gd_scene load_steps=5 format=2] +[gd_scene load_steps=6 format=2] [ext_resource path="res://Enemies/Dino.gd" type="Script" id=1] [sub_resource type="CapsuleShape" id=1] -radius = 3.0 -height = 8.10705 +radius = 5.0 +height = 5.45307 [sub_resource type="ArrayMesh" id=2] surfaces/0 = { @@ -23,14 +23,15 @@ surfaces/0 = { radius = 1.61282 height = 2.07838 -[node name="Dino" type="KinematicBody" groups=[ -"Dino", -]] +[sub_resource type="SphereShape" id=4] +radius = 3.47625 + +[node name="Dino" type="KinematicBody"] script = ExtResource( 1 ) speed = 10.0 [node name="CollisionShape" type="CollisionShape" parent="."] -transform = Transform( 1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 7, 0 ) +transform = Transform( 1, 0, 0, 0, -5.96046e-08, 1, 0, -1, -5.96046e-08, 0, 8, 0 ) shape = SubResource( 1 ) [node name="Plane" type="MeshInstance" parent="."] @@ -41,3 +42,11 @@ material/0 = null [node name="CollisionShape2" type="CollisionShape" parent="."] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 4.76837e-07, 13.5719, -6 ) shape = SubResource( 3 ) + +[node name="Area" type="Area" parent="." groups=[ +"Dino", +]] + +[node name="CollisionShape" type="CollisionShape" parent="Area"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 5, -4 ) +shape = SubResource( 4 ) diff --git a/WikiJam/Level/Objects/Crystal.tscn b/WikiJam/Level/Objects/Crystal.tscn index 2788b02..b330728 100644 --- a/WikiJam/Level/Objects/Crystal.tscn +++ b/WikiJam/Level/Objects/Crystal.tscn @@ -10,13 +10,13 @@ transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 2, 0 ) script = ExtResource( 1 ) -[node name="CrystalBody" type="StaticBody" parent="." groups=[ +[node name="Area" type="Area" parent="." groups=[ "Crystal", ]] -[node name="CollisionShape" type="CollisionShape" parent="CrystalBody"] +[node name="CollisionShape" type="CollisionShape" parent="Area"] shape = SubResource( 1 ) -[node name="MeshInstance" type="MeshInstance" parent="CrystalBody"] +[node name="MeshInstance" type="MeshInstance" parent="."] mesh = SubResource( 2 ) material/0 = null diff --git a/WikiJam/Player/Player.gd b/WikiJam/Player/Player.gd index b493a99..ab4c76d 100644 --- a/WikiJam/Player/Player.gd +++ b/WikiJam/Player/Player.gd @@ -5,6 +5,7 @@ export(NodePath) var body_nodepath export(NodePath) var camera_nodepath export(NodePath) var animation_nodepath export(NodePath) var ui_nodepath +export(NodePath) var interact_area_nodepath # const const GRAVITY = -24.8 @@ -24,6 +25,7 @@ var _camera: Camera var _animation: AnimationPlayer var _interface: Control var _sprintometer: ProgressBar +var _interact_area: Area var _dir = Vector3() var _vel = Vector3() var _is_sprinting @@ -47,6 +49,11 @@ func _ready(): _sprintometer = _interface.get_node("ProgressBar") assert(null != _sprintometer) + _interact_area = get_node(interact_area_nodepath) as Area + assert(null != _interact_area) + + _interact_area.connect("area_entered", self, "_on_interact_entered") + # Setup mouse look Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) @@ -54,7 +61,6 @@ func _ready(): func _physics_process(delta): _process_input() _process_movement(delta) - _process_collision() #Logger.info("sprintVal: " + String(_sprintVal)) @@ -115,20 +121,12 @@ func _process_animations(): _sprintometer.value = _sprintVal -func _process_collision(): - var collCount = get_slide_count() - if collCount > 0: - #Logger.debug("Collide count: ", collCount) - for i in collCount: - var collision = get_slide_collision(i) - #Logger.debug("Collided with: ", collision.collider.name) - #TODO: replace with groups - if collision.collider.name == "CrystalBody": - #Logger.debug("removing crystal...") - collision.collider.queue_free() - _interface.increaseScore() - elif collision.collider.name == "Dino": - _interface.gameOver() +func _on_interact_entered(area: Area): + if area.is_in_group("Crystal"): + area.get_parent().queue_free() # Assuming crystal area is always parent of crystal root + _interface.increaseScore() + elif area.is_in_group("Dino"): + _interface.gameOver() func _input(event): diff --git a/WikiJam/Player/Player.tscn b/WikiJam/Player/Player.tscn index cccfee2..129ac5c 100644 --- a/WikiJam/Player/Player.tscn +++ b/WikiJam/Player/Player.tscn @@ -53,6 +53,7 @@ body_nodepath = NodePath("Body") camera_nodepath = NodePath("Camera") animation_nodepath = NodePath("WalkAnimationPlayer") ui_nodepath = NodePath("HUD") +interact_area_nodepath = NodePath("InteractArea") [node name="Body" type="Spatial" parent="."]