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)