From 611cb87df4df30d81b3544a25d51816689ba6b9e Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 20 Jan 2018 16:10:14 -0500 Subject: [PATCH] Detect collisions between player and objective Unfortunately, apply_impulse seems to have no effect right now. More research is needed. --- scenes/heroes/0.tscn | 4 +++- scenes/player.tscn | 6 ++++-- scenes/world.tscn | 14 ++++++++------ scripts/player.gd | 11 +++++++++++ 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/scenes/heroes/0.tscn b/scenes/heroes/0.tscn index 4e4fbd3..4b0c300 100644 --- a/scenes/heroes/0.tscn +++ b/scenes/heroes/0.tscn @@ -20,7 +20,9 @@ radial_segments = 64 rings = 8 _sections_unfolded = [ "Resource" ] -[node name="RigidBody" type="KinematicBody"] +[node name="RigidBody" type="KinematicBody" groups=[ +"player", +]] input_ray_pickable = true input_capture_on_drag = false diff --git a/scenes/player.tscn b/scenes/player.tscn index 7cf0d6b..08a1e25 100644 --- a/scenes/player.tscn +++ b/scenes/player.tscn @@ -20,7 +20,9 @@ radial_segments = 64 rings = 8 _sections_unfolded = [ "Resource" ] -[node name="RigidBody" type="KinematicBody" index="0"] +[node name="RigidBody" type="KinematicBody" index="0" groups=[ +"player", +]] input_ray_pickable = true input_capture_on_drag = false @@ -34,7 +36,7 @@ axis_lock_angular_y = false axis_lock_angular_z = false collision/safe_margin = 0.001 script = ExtResource( 1 ) -_sections_unfolded = [ "Angular", "Collision", "Linear", "Transform", "Visibility" ] +_sections_unfolded = [ "Angular", "Axis Lock", "Collision", "Linear", "Transform", "Visibility", "collision" ] [node name="Body" type="CollisionShape" parent="." index="0"] diff --git a/scenes/world.tscn b/scenes/world.tscn index e04579b..3572962 100644 --- a/scenes/world.tscn +++ b/scenes/world.tscn @@ -31,7 +31,7 @@ radial_segments = 64 rings = 32 is_hemisphere = false -[node name="world" type="Spatial" index="0"] +[node name="world" type="Spatial"] [node name="DirectionalLight" type="DirectionalLight" parent="." index="0"] @@ -161,7 +161,9 @@ constant_angular_velocity = Vector3( 0, 0, 0 ) shape = SubResource( 1 ) disabled = false -[node name="Objective" type="RigidBody" parent="." index="7"] +[node name="Objective" type="RigidBody" parent="." index="7" groups=[ +"objective", +]] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -91.3336, 3.19767, 4.06596 ) input_ray_pickable = true @@ -175,8 +177,8 @@ bounce = 0.0 gravity_scale = 1.0 custom_integrator = false continuous_cd = false -contacts_reported = 0 -contact_monitor = false +contacts_reported = 8 +contact_monitor = true sleeping = false can_sleep = true axis_lock_linear_x = true @@ -190,7 +192,7 @@ linear_damp = -1.0 angular_velocity = Vector3( 0, 0, 0 ) angular_damp = -1.0 script = ExtResource( 3 ) -_sections_unfolded = [ "Axis Lock", "Linear", "Transform" ] +_sections_unfolded = [ "Axis Lock", "Collision", "Linear", "Transform", "Visibility" ] [node name="CollisionShape" type="CollisionShape" parent="Objective" index="0"] @@ -231,7 +233,7 @@ custom_integrator = false continuous_cd = false contacts_reported = 0 contact_monitor = false -sleeping = false +sleeping = true can_sleep = true axis_lock_linear_x = false axis_lock_linear_y = false diff --git a/scripts/player.gd b/scripts/player.gd index 219f901..a2a5446 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -21,6 +21,7 @@ var timer = 0 var walk_speed = 3 var jump_speed = 15 +var weight = 500 var health = 100 var stamina = 10000 var ray_length = 10 @@ -107,8 +108,18 @@ func control_player(delta): velocity.z *= friction velocity.y += gravity velocity += direction * air_accel + + # Just for testing TODO + if Input.is_action_pressed("jump"): + velocity.y += jump_speed * 0.1 move_and_slide(velocity, Vector3(0, 1, 0)) + + for i in range(get_slide_count()): + var collision = get_slide_collision(i) + if collision.collider.is_in_group("objective"): + collision.collider.apply_impulse(Vector3(-5,0,-5), Vector3(0, -weight, 0)) + print("collided with the objective!") func _exit_scene(): Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)