Godot 4.2.1
Here is my code:
extends Sprite2D
var speed = 300
var screensize
var pos
var velocity = Vector2(100, 50)
func _ready():
screensize = get_viewport_rect().size.x
pos = screensize / 2
set_process(true)
pass
func _process(delta):
if Input.is_action_pressed(“ui_right”) or Input.is_key_pressed(KEY_D):
position.x += speed * delta
if Input.is_action_pressed(“ui_left”) or Input.is_key_pressed(KEY_A):
position.x -= speed * delta
if Input.is_action_pressed(“ui_up”) or Input.is_key_pressed(KEY_W):
position.y -= speed * delta
if Input.is_action_pressed(“ui_down”) or Input.is_key_pressed(KEY_S):
position.y += speed * delta
if pos.x >= screensize.width or pos.x <= 0:
velocity.x *= -1
if pos.y >= screensize.height or pos.y <= 0:
velocity.y *= -1
pos += velocity * delta
set_position(pos)
So im trying to follow a tutorial i found on Godot engine and part of it talks about making a sprite bounce/ hit off the wall. However every time i try to do it keeps on giving me the error: Invalid get Index ‘x’ (on base:‘float’) and im overall just confused if its a piece of code im missing or not.
If you have any suggestions or a solution to fix this then let me know ASAP!