This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

this is how my code looks i tried everything re typing it taking other ppl codes looking at other q&a watching yt and trying to make a little change from my some what type of experience with gd script and nothing is working ONLY the vertical movment is working and only going up left so i dont really know what to do

 extends Area2D
export var speed = 400
var screen_size

func _ready():
    screen_size = get_viewport_rect().size

func _process(delta):
    var velocity = Vector2.ZERO
    if Input.is_action_pressed("move_right"):
        velocity.x += 1
    if Input.is_action_pressed("move_left"):
        velocity.x -= 1
    if Input.is_action_pressed("move_down"):
        velocity.y += 1
    if Input.is_action_pressed("move_up"):
        velocity.y -= 1
    if velocity.length() > 0:
        velocity = velocity.normalized() * speed


    position += velocity * delta
    position.x = clamp(position.x, 0, screen_size.x)
    position.x = clamp(position.y, 0, screen_size.y)
Godot version 3.4.4
in Engine by (19 points)

1 Answer

+1 vote

Your line of code position.x = clamp(position.y, 0, screen_size.y) should be position.y = clamp(position.y, 0, screen_size.y) I believe. Your getting the x and y axis mixed up

by (1,438 points)

ohhh thank you i really didnt notice even tho i re typed it multiple times anyway thank you this rlly helped

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.