Advertisement
ignacy123

Gemetry Dash - Player.gd

Aug 8th, 2023 (edited)
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. extends Actor
  2.  
  3. export var stomp_impulse: = 1000.0
  4.  
  5. func _on_EnemyDetector_area_entered(area):
  6. velocity = calculate_stomp_velocity(velocity, stomp_impulse)
  7.  
  8. func _physics_process(delta) -> void:
  9. var direction: = get_direction()
  10. velocity = calculate_move_velocity(velocity,
  11. direction,
  12. speed)
  13. velocity = move_and_slide(velocity, FLOOR_NORMAL, true)
  14.  
  15.  
  16. func get_direction() -> Vector2:
  17. return Vector2(
  18. Input.get_action_strength("move_right") - Input.get_action_strength("move_left"),
  19. -1.0 if is_on_floor() and Input.is_action_just_pressed("jump") else 0.0
  20. )
  21.  
  22. func calculate_move_velocity(
  23. linear_velocity: Vector2,
  24. direction: Vector2,
  25. speed: Vector2
  26. ) -> Vector2:
  27. var new_velocity: = linear_velocity
  28. new_velocity.x = speed.x * direction.x
  29. if direction.y != 0.0:
  30. new_velocity.y = speed.y * direction.y
  31. return new_velocity
  32.  
  33. func calculate_stomp_velocity(linear_velocity: Vector2, impulse: float) -> Vector2:
  34. var out: = linear_velocity
  35. out.y = -impulse
  36. return out
  37.  
  38. func _on_EnemyDetector_body_entered(body):
  39. queue_free()
  40.  
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement