Browse Source

Detect collisions between player and objective

Unfortunately, apply_impulse seems to have no effect right now. More
research is needed.
master
Luna 7 years ago
parent
commit
611cb87df4
4 changed files with 26 additions and 9 deletions
  1. +3
    -1
      scenes/heroes/0.tscn
  2. +4
    -2
      scenes/player.tscn
  3. +8
    -6
      scenes/world.tscn
  4. +11
    -0
      scripts/player.gd

+ 3
- 1
scenes/heroes/0.tscn View File

@ -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


+ 4
- 2
scenes/player.tscn View File

@ -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"]


+ 8
- 6
scenes/world.tscn View File

@ -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


+ 11
- 0
scripts/player.gd View File

@ -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)


Loading…
Cancel
Save