3D model not stopping at edge of the screen.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Archtects
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

:bust_in_silhouette: Reply From: PixiePal

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.

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.

Archtects | 2018-08-01 11:24

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

Archtects | 2018-08-01 11:31