Improve collision, use more Areas instead of bodys
This commit is contained in:
parent
7f4f2a8f5b
commit
eb2cd95a09
@ -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 )
|
||||
|
@ -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
|
||||
|
@ -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,19 +121,11 @@ 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()
|
||||
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 collision.collider.name == "Dino":
|
||||
elif area.is_in_group("Dino"):
|
||||
_interface.gameOver()
|
||||
|
||||
|
||||
|
@ -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="."]
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user