RemotePlayer.gd 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. extends KinematicBody2D
  2. signal remoteplayer_velchange(velocity)
  3. # Declare member variables here. Examples:
  4. # var a = 2
  5. # var b = "text"
  6. const GRAVITY = 200.0
  7. const WALK_SPEED = 200
  8. var velocity = Vector2()
  9. var target = Vector2()
  10. var id = 0
  11. # Called when the node enters the scene tree for the first time.
  12. #func _ready():
  13. func _physics_process(delta):
  14. var velocity_old = velocity
  15. #print("ist:", self.position, "soll:", target)
  16. velocity.x = (target.x - self.position.x)
  17. velocity.y = (target.y - self.position.y)
  18. if velocity_old != velocity:
  19. emit_signal("remoteplayer_velchange", velocity)
  20. # We don't need to multiply velocity by delta because "move_and_slide" already takes delta time into account.
  21. # The second parameter of "move_and_slide" is the normal pointing up.
  22. # In the case of a 2D platformer, in Godot, upward is negative y, which translates to -1 as a normal.
  23. velocity = move_and_slide(velocity, Vector2(0, -1))
  24. for i in get_slide_count():
  25. var collision = get_slide_collision(i)
  26. if collision:
  27. pass
  28. func setTarget(targetid, pos):
  29. if targetid == id:
  30. target = pos
  31. # Called every frame. 'delta' is the elapsed time since the previous frame.
  32. #func _process(delta):
  33. #