![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | scrubswithnosleeves |
Hello!
Godot 3.2.2 stable on macOS
I am trying to replicate the following motion from the Godot docs: Interpolation — Godot Engine (latest) documentation in English
here is the code they provide:
const FOLLOW_SPEED = 4.0
func _physics_process(delta):
var mouse_pos = get_local_mouse_position()
$Sprite.position = $Sprite.position.linear_interpolate(mouse_pos, delta * FOLLOW_SPEED)
This works as long as the scene is set up so that the .position
your referencing is a child of the node that contains the script.
However, if I put the following code into a script in the Sprite node itself:
const FOLLOW_SPEED = 4.0
func _physics_process(delta):
var mouse_pos = get_local_mouse_position()
position = position.linear_interpolate(mouse_pos, delta * FOLLOW_SPEED)
I get the following odd movement:
It is also odd that when I print mouse_pos
and position
, they still say they are relatively equal to each other. Can anyone tell me what I am doing wrong or if this is a bug?
I was planning on using something like this to make an enemy that followed a certain distance behind the player, and I wanted to put the lerp movement code withing the enemy node script itself. I’m pretty comfortable with lerping, but I don’t get what is happening in this case.
Thanks in advance!
try self.position
sirAlexDev | 2020-08-31 19:30
Tried that :(. No change whatsoever. Also tried global_position
.
scrubswithnosleeves | 2020-08-31 19:32