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.

56 lines
1.8 KiB

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