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.

73 lines
2.3 KiB

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