A team game with an emphasis on movement (with no shooting), inspired by Overwatch and Zineth
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
2.0 KiB

  1. extends "res://scripts/player.gd"
  2. const wallride_speed_necessary = 1.5
  3. const wallride_leap_height = 48
  4. const wallride_leap_side = 6
  5. const wallride_leap_build = 0.01
  6. var since_on_wall = 0
  7. var last_wall_normal = Vector3()
  8. var wallride_forgiveness = .150
  9. func _ready():
  10. ._ready()
  11. walk_speed *= 1.2
  12. air_accel *= 3
  13. jump_speed *= 1
  14. walk_speed_build *= 2
  15. air_speed_build *= 3
  16. func control_player(state):
  17. .control_player(state)
  18. wallride(state)
  19. func wallride(state):
  20. var ray = get_node("Ray")
  21. var vel = state.get_linear_velocity()
  22. # If our feet aren't touching, but we are colliding, we are wall-riding
  23. if !ray.is_colliding() and get_colliding_bodies() and vel.length() > wallride_speed_necessary:
  24. last_wall_normal = state.get_contact_local_normal(0)
  25. # Make sure it isn't the floor
  26. if last_wall_normal.dot(Vector3(0,1,0)) < 0.95:
  27. since_on_wall = 0
  28. else:
  29. since_on_wall += state.get_step()
  30. debug_node.set_text(str(since_on_wall < wallride_forgiveness))
  31. if since_on_wall < wallride_forgiveness:
  32. # Add zero gravity
  33. set_gravity_scale(0)
  34. # Remove any momentum we may have
  35. state.set_linear_velocity(Vector3(vel.x, 0, vel.z))
  36. # Because 1/2 of our energy is wasted in the wall, get more forwards/backwards here:
  37. var aim = get_node("Yaw").get_global_transform().basis
  38. if Input.is_action_pressed("move_forwards"):
  39. apply_impulse(Vector3(), -air_accel * aim[2] * get_mass())
  40. if Input.is_action_pressed("move_backwards"):
  41. apply_impulse(Vector3(), air_accel * aim[2] * get_mass())
  42. # Allow jumping (for wall hopping!)
  43. if Input.is_action_just_pressed("jump"):
  44. var build_factor = 1 + switch_charge * wallride_leap_build
  45. var jump_impulse = build_factor * wallride_leap_side * last_wall_normal
  46. jump_impulse.y += build_factor * wallride_leap_height
  47. set_gravity_scale(1) # Jumping requires gravity
  48. state.apply_impulse(Vector3(), jump_impulse * get_mass())
  49. else:
  50. # We need to return to falling (we aren't riding anymore)
  51. set_gravity_scale(1)
  52. state.integrate_forces()