func _physics_process(delta):
if Input.is_action_pressed(“ui_down”):
sprite.get_viewport_transform().x = sprite.get_viewport_transform().x + vel
sprite.draw_set_transfor
extends KinematicBody2D
var vel = Vector2(1,1)
var sprite
func _ready():
sprite = get_node("Sprite")
set_process(true)
func _physics_process(delta):
if Input.is_action_pressed("ui_down"):
position.y = position.y + 1
position.x = 100
sprite.position = sprite.position + vel
This code works for moving sprite in the scene.
Have a nice day
This won’t work correctly. KinematicBody2D must be moved with move_and_collide() or move_and_slide() or it will not detect collisions.
There are also some large problems with this code.
In your code, you’re changing the position twice - adding 1 to position.y and then locking position.x to 100 for the KinematicBody2D. Then you’re moving the child sprite by (1,1). This seems crazy. Your kinematic body is going to slowly move straight down and your child sprite diagonally, slowly getting farther and farther apart.