Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

gdscript top-down 2d movement

extends KinematicBody2D

export (int) var speed = 200

var velocity = Vector2()

func get_input():
    velocity = Vector2()
    if Input.is_action_pressed("ui_right"):
        velocity.x += 1
    if Input.is_action_pressed("ui_left"):
        velocity.x -= 1
    if Input.is_action_pressed("ui_down"):
        velocity.y += 1
    if Input.is_action_pressed("ui_up"):
        velocity.y -= 1
    velocity = velocity.normalized() * speed

func _physics_process(delta):
    get_input()
    velocity = move_and_slide(velocity)
Comment

PREVIOUS NEXT
Code Example
Python :: pandas dataframe aggregations 
Python :: ubuntu download file command line 
Python :: python min length list of strings 
Python :: check if response is 200 python 
Python :: torch concat matrix 
Python :: aioschedule python 
Python :: python check if string starting with substring from list ltrim python 
Python :: python remove non empty read only directory 
Python :: get package share vs Find Package Share 
Python :: python selenium button is not clickable at point 
Python :: calculate the addition of two lists in python 
Python :: split imagedatagenerator into x_train and y_train 
Python :: pandas count rows with value 
Python :: serializers.py include all fields 
Python :: tkinter maximize window 
Python :: flask oneid 
Python :: virtual env in python 
Python :: ValueError: There may be at most 1 Subject headers in a message 
Python :: find matches between two lists python 
Python :: python argparse 
Python :: converting bool to 1 if it has true and if it is false print 1 
Python :: python open file same folder 
Python :: pygame flip image 
Python :: django getting started 
Python :: how to clear checkbox in tkinter 
Python :: list to string python 
Python :: all permutations python 
Python :: rabbitmq pika username password 
Python :: drop unamed columns in pandas 
Python :: how to remove all characters from a string in python 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =