`my code uses position but if i try position.x it doesnt work here is what i have
extends AnimatableBody2D @onready var raycast = $RayCast2D
var MOVE_SPEED = 1
Called every frame. ‘delta’ is the elapsed time since the previous frame.
func _process(delta: float) → void:
var location = raycast.get_collision_point()
print(location)
if raycast.is_colliding():
position.x = position.x.lerp(location, delta * MOVE_SPEED)
$AnimatedSprite2D.play("idle")
I guess you are getting an error because you are calling lerp on a float. It’s always helpful to post the errors you are getting (in addition to formatting your code as @jesusemora mentioned).
In any case, lerp is a functions on Vectors not floats. You could get ‘x’ from the interpolated vector and only then assign it to the position or simply implement ‘lerp’ yourself (or use the global function). See Interpolation — Godot Engine (stable) documentation in English.
Edit: Just if it’s not clear what I mean: Move the .x after the lerp. Vector2.lerp returns a vector.