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]
|
[ext_resource path="res://Enemies/Dino.gd" type="Script" id=1]
|
||||||
|
|
||||||
[sub_resource type="CapsuleShape" id=1]
|
[sub_resource type="CapsuleShape" id=1]
|
||||||
radius = 3.0
|
radius = 5.0
|
||||||
height = 8.10705
|
height = 5.45307
|
||||||
|
|
||||||
[sub_resource type="ArrayMesh" id=2]
|
[sub_resource type="ArrayMesh" id=2]
|
||||||
surfaces/0 = {
|
surfaces/0 = {
|
||||||
@ -23,14 +23,15 @@ surfaces/0 = {
|
|||||||
radius = 1.61282
|
radius = 1.61282
|
||||||
height = 2.07838
|
height = 2.07838
|
||||||
|
|
||||||
[node name="Dino" type="KinematicBody" groups=[
|
[sub_resource type="SphereShape" id=4]
|
||||||
"Dino",
|
radius = 3.47625
|
||||||
]]
|
|
||||||
|
[node name="Dino" type="KinematicBody"]
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
speed = 10.0
|
speed = 10.0
|
||||||
|
|
||||||
[node name="CollisionShape" type="CollisionShape" parent="."]
|
[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 )
|
shape = SubResource( 1 )
|
||||||
|
|
||||||
[node name="Plane" type="MeshInstance" parent="."]
|
[node name="Plane" type="MeshInstance" parent="."]
|
||||||
@ -41,3 +42,11 @@ material/0 = null
|
|||||||
[node name="CollisionShape2" type="CollisionShape" parent="."]
|
[node name="CollisionShape2" type="CollisionShape" parent="."]
|
||||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 4.76837e-07, 13.5719, -6 )
|
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 4.76837e-07, 13.5719, -6 )
|
||||||
shape = SubResource( 3 )
|
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 )
|
transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 2, 0 )
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
|
|
||||||
[node name="CrystalBody" type="StaticBody" parent="." groups=[
|
[node name="Area" type="Area" parent="." groups=[
|
||||||
"Crystal",
|
"Crystal",
|
||||||
]]
|
]]
|
||||||
|
|
||||||
[node name="CollisionShape" type="CollisionShape" parent="CrystalBody"]
|
[node name="CollisionShape" type="CollisionShape" parent="Area"]
|
||||||
shape = SubResource( 1 )
|
shape = SubResource( 1 )
|
||||||
|
|
||||||
[node name="MeshInstance" type="MeshInstance" parent="CrystalBody"]
|
[node name="MeshInstance" type="MeshInstance" parent="."]
|
||||||
mesh = SubResource( 2 )
|
mesh = SubResource( 2 )
|
||||||
material/0 = null
|
material/0 = null
|
||||||
|
@ -5,6 +5,7 @@ export(NodePath) var body_nodepath
|
|||||||
export(NodePath) var camera_nodepath
|
export(NodePath) var camera_nodepath
|
||||||
export(NodePath) var animation_nodepath
|
export(NodePath) var animation_nodepath
|
||||||
export(NodePath) var ui_nodepath
|
export(NodePath) var ui_nodepath
|
||||||
|
export(NodePath) var interact_area_nodepath
|
||||||
|
|
||||||
# const
|
# const
|
||||||
const GRAVITY = -24.8
|
const GRAVITY = -24.8
|
||||||
@ -24,6 +25,7 @@ var _camera: Camera
|
|||||||
var _animation: AnimationPlayer
|
var _animation: AnimationPlayer
|
||||||
var _interface: Control
|
var _interface: Control
|
||||||
var _sprintometer: ProgressBar
|
var _sprintometer: ProgressBar
|
||||||
|
var _interact_area: Area
|
||||||
var _dir = Vector3()
|
var _dir = Vector3()
|
||||||
var _vel = Vector3()
|
var _vel = Vector3()
|
||||||
var _is_sprinting
|
var _is_sprinting
|
||||||
@ -47,6 +49,11 @@ func _ready():
|
|||||||
_sprintometer = _interface.get_node("ProgressBar")
|
_sprintometer = _interface.get_node("ProgressBar")
|
||||||
assert(null != _sprintometer)
|
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
|
# Setup mouse look
|
||||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||||
|
|
||||||
@ -54,7 +61,6 @@ func _ready():
|
|||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
_process_input()
|
_process_input()
|
||||||
_process_movement(delta)
|
_process_movement(delta)
|
||||||
_process_collision()
|
|
||||||
#Logger.info("sprintVal: " + String(_sprintVal))
|
#Logger.info("sprintVal: " + String(_sprintVal))
|
||||||
|
|
||||||
|
|
||||||
@ -115,20 +121,12 @@ func _process_animations():
|
|||||||
_sprintometer.value = _sprintVal
|
_sprintometer.value = _sprintVal
|
||||||
|
|
||||||
|
|
||||||
func _process_collision():
|
func _on_interact_entered(area: Area):
|
||||||
var collCount = get_slide_count()
|
if area.is_in_group("Crystal"):
|
||||||
if collCount > 0:
|
area.get_parent().queue_free() # Assuming crystal area is always parent of crystal root
|
||||||
#Logger.debug("Collide count: ", collCount)
|
_interface.increaseScore()
|
||||||
for i in collCount:
|
elif area.is_in_group("Dino"):
|
||||||
var collision = get_slide_collision(i)
|
_interface.gameOver()
|
||||||
#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 _input(event):
|
func _input(event):
|
||||||
|
@ -53,6 +53,7 @@ body_nodepath = NodePath("Body")
|
|||||||
camera_nodepath = NodePath("Camera")
|
camera_nodepath = NodePath("Camera")
|
||||||
animation_nodepath = NodePath("WalkAnimationPlayer")
|
animation_nodepath = NodePath("WalkAnimationPlayer")
|
||||||
ui_nodepath = NodePath("HUD")
|
ui_nodepath = NodePath("HUD")
|
||||||
|
interact_area_nodepath = NodePath("InteractArea")
|
||||||
|
|
||||||
[node name="Body" type="Spatial" parent="."]
|
[node name="Body" type="Spatial" parent="."]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user