godot code for movement

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

3.75
8
Hellnar 100 points

                                    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 * position)
	

3.75 (8 Votes)
0
4.43
7
Jimm 100 points

                                    #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)

4.43 (7 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
minecraft movement code in godot godot 3d movement code top down movement in godot hwo to make the player move in godot godot movement animation godot node movement movement code for godot how to add top down movement in godot 3d movement in godot movement godot tutorial godot top down movement animation godot basic movement 3d movement godot how to make 3d player movement godot how to make player movement in godot how to make player movement godot godot, 3d movement godot player movement script godot turn based movement top down movement godot godot 3d movement script godot movement examples godot 3d movement tutorial Godot C# 3D movement godot 3d movement godot movement c# godot top down movement godot code for movement for topdown game player movement in godot godot simple movement godot simple player simple movement script for gdscript rotaion in godot 2d godot player movement code move in godot godot fps movement fps movement in godot godot wasd movement how to make 2D acceleration in godot gdscript movement script godot simple 2d movement godot diagonal movement bullet move toward godot godot move sprite with keys gdscript move current node gdscript movement movil gdscript movement simple movement script gdscript godot sine movement how to make a character move in godot godot movement code 2d godot movement code godot rigidbody move x and y 2d¨ make a charachter auto move in godot godot 2d controls moving godot icon movement godot move character up godot movement script 2d rpg gds movement script godot moveto move up godot rpg movement godot godot movement player movement godot godot engine charactar movement movement godot 2d movement godot movement in 2d godot Godot Engine Movement 2D godot c# move node on input godot moving player godot x and y movement godot player movement godot player not moving c# Godot Movement 2D Godot Mobvemnt move player godot player moement in godot godot move 2D Node from script godot 2d walking godot rotate object 2d to movement direction simple movement in godot 2d simple movement in godot simple gdscript movement 2d simplae gdscript movement basic gdscript movement godot 2d movement godot rpg movement 2d godot move movement into seperate script godot move move c# godot how to make a constant forward movement in godot 3d with code how to make a constant forward movement in godot godot move block certion amount of pixels how to make a player move in godot how to stop node from moving on x axis godot godot 3.2.2 simple side scroller movement code godot engine player move other objects move 2d object godot godot have arrow rotating for where character should go movement in godot code for movement in godot 2d what's the godot code for moving forward godot movent code godot c# move towards godot code for movement
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source