user60343
0
Q:

movement in godot

extends KinematicBody2D

var velocity = Vector2.ZERO

func _physics_process(delta):
	if Input. is_action_pressed("ui_right"):
		position.x += 4
	elif Input. is_action_pressed("ui_left"):
		position.x -= 4
	elif Input. is_action_pressed("ui_up"):
		position.y -= 4
	elif Input. is_action_pressed("ui_down"):
		position.y += 4

	move_and_collide(velocity)


#this one it the best and most simple one
2
#3d
extends KinematicBody

var speed = 200
var motion = Vector2()

func _physics_process(delta):
	if Input. is_action_pressed("ui_right"):
		motion.x += speed
	elif Input. is_action_pressed("ui_left"):
		motion.x -= speed
	elif Input. is_action_pressed("ui_up"):
		motion.z -= speed
	elif Input. is_action_pressed("ui_down"):
		motion.z += speed
	else:
		motion.x = 0
		

	move_and_collide(motion)
1

New to Communities?

Join the community