0 votes
extends KinematicBody

var speed = 350
var direction = Vector3()
var screenWidth = ProjectSettings.get_setting("display/window/size/width")

func _ready():
    pass

func _physics_process(delta):
    direction = Vector3(0, 0, 0)
    if Input.is_action_pressed("ui_left"):
        if translation == Vector3(-2.430556, 0, 0):
            print() 
        else:
            direction.x -= 1
    if Input.is_action_pressed("ui_right"):
        if translation == Vector3(2.430556, 0, 0):
            print()
        else:
            direction.x += 1
    direction = direction.normalized()
    print(translation)
    direction = direction * speed * delta
    move_and_slide(direction, Vector3(0, 1, 0))

Character should stop at Vector3 Cords
The character stops on the Left one. But doesn't stop on the Right.
Just Keeps Going.

Is there a better way of doing this. Or have i just done something wrong?
Any help would be appreciated

in Engine by (51 points)

1 Answer

+1 vote

Don't have editor out atm but you might want to check your second IF statement. It looks like it's skipping that condition and jumping to the else, which may explain why the character is going off-screen.

You would also implement that the character "stops" as far as the camera can go.

by (97 points)

you might want to check your second IF statement. It looks like it's skipping that condition and jumping to the else, which may explain why the character is going off-screen.

I see this. But Why exactly? I cant work out Why it would be skipping it.

So no idea why it was ignoring it so i changed it to:

    if translation < Vector3(2.430556, 0, 0):
        direction.x += 1
        rotation.z += 0.02
    else:
        print("woo")

And now it works fine. Thanks anyway

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.