Advertisement
actuallykron

Godot 4 - Easy Top Down Movement

Sep 23rd, 2023 (edited)
422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
GDScript 0.46 KB | Source Code | 0 0
  1. extends CharacterBody2D
  2.  
  3. var speed = 300
  4.  
  5. func _physics_process(delta):
  6.     # Resets velocity
  7.     velocity = Vector2()
  8.    
  9.     # These inputs will need to be created in the input map
  10.     if Input.is_action_pressed("left"):
  11.         velocity.x -= 1
  12.     if Input.is_action_pressed("right"):
  13.         velocity.x += 1
  14.     if Input.is_action_pressed("up"):
  15.         velocity.y -= 1
  16.     if Input.is_action_pressed("down"):
  17.         velocity.y += 1
  18.        
  19.     velocity = velocity * speed
  20.     move_and_slide()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement