1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- extends KinematicBody2D
- signal remoteplayer_velchange(velocity)
- # Declare member variables here. Examples:
- # var a = 2
- # var b = "text"
- const GRAVITY = 200.0
- const WALK_SPEED = 200
- var velocity = Vector2()
- var target = Vector2()
- var id = 0
- # Called when the node enters the scene tree for the first time.
- #func _ready():
- func _physics_process(delta):
- var velocity_old = velocity
- #print("ist:", self.position, "soll:", target)
- velocity.x = (target.x - self.position.x)
- velocity.y = (target.y - self.position.y)
-
- if velocity_old != velocity:
- emit_signal("remoteplayer_velchange", velocity)
-
- # We don't need to multiply velocity by delta because "move_and_slide" already takes delta time into account.
- # The second parameter of "move_and_slide" is the normal pointing up.
- # In the case of a 2D platformer, in Godot, upward is negative y, which translates to -1 as a normal.
- velocity = move_and_slide(velocity, Vector2(0, -1))
- for i in get_slide_count():
- var collision = get_slide_collision(i)
- if collision:
- pass
-
- func setTarget(targetid, pos):
- if targetid == id:
- target = pos
-
- # Called every frame. 'delta' is the elapsed time since the previous frame.
- #func _process(delta):
- #
-
|