1extends KinematicBody2D
2
3var velocity = Vector2.ZERO
4
5func _physics_process(delta):
6 if Input. is_action_pressed("ui_right"):
7 position.x += 4
8 elif Input. is_action_pressed("ui_left"):
9 position.x -= 4
10 elif Input. is_action_pressed("ui_up"):
11 position.y -= 4
12 elif Input. is_action_pressed("ui_down"):
13 position.y += 4
14
15 move_and_collide(velocity)
16
17
18#this one it the best and most simple one
1#3d
2extends KinematicBody
3
4var speed = 200
5var motion = Vector2()
6
7func _physics_process(delta):
8 if Input. is_action_pressed("ui_right"):
9 motion.x += speed
10 elif Input. is_action_pressed("ui_left"):
11 motion.x -= speed
12 elif Input. is_action_pressed("ui_up"):
13 motion.z -= speed
14 elif Input. is_action_pressed("ui_down"):
15 motion.z += speed
16 else:
17 motion.x = 0
18
19
20 move_and_collide(motion)
1var velocity = Vector2.ZERO
2
3func _physics_process(delta):
4 if Input. is_action_pressed("ui_right"):
5 position.x += 4
6 elif Input. is_action_pressed("ui_left"):
7 position.x -= 4
8 elif Input. is_action_pressed("ui_up"):
9 position.y -= 4
10 elif Input. is_action_pressed("ui_down"):
11 position.y += 4
12 move_and_collide(velocity * position)
13