How to get only X coordinates of player from other script

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By toivocat

I was making a 2D game where the player has to run from a boulder that is chasing them. But whenever the player jumps the boulder also moves up so I need to only get the X coordinates of the player so that it will stay on the ground. This is the boulder code:

	extends KinematicBody2D

var nearest_player
var velocity = Vector2()
var collide

export var gravity = 9000000000000000

export var health = 5
export var speed = 1.0
export var damage = 1
export var wait_time = 0.1
var tile_size = 10

var isMove = true
var isAttack = false

func _ready():


func get_target():
	var players = []

	players += get_tree().get_nodes_in_group("player")

	if players.size() > 0:
		nearest_player = players[0]

	for player in players:
		if player.global_position.distance_to(global_position) < nearest_player.global_position.distance_to(global_position):
			nearest_player = player

func _process(delta):
	if speed != 500.0:
		speed += 0.1
	velocity.x = 0
	velocity.y += gravity
	if isMove and is_instance_valid(nearest_player):
		velocity = (nearest_player - global_position).normalized() * speed

		collide = move_and_slide(velocity)

	for i in get_slide_count():
		var collision = get_slide_collision(i)
		var collider = collision.collider
		if is_instance_valid(collider) and collider.is_in_group("player"):

	if health <= 0:

func enemy_hit(dmg):
	health -= dmg
:bust_in_silhouette: Reply From: Gluon

You can do something like this

var vec = Vector2()

func find_player():
	vec = get_node("Root/tothe/PlayerSprite").position