Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | slu | |
Old Version | Published before Godot 3 was released. |
Hi, i have node called “ghost” which should follow the player everywhere, however, it does not.
It just keeps going to the right, even thought it counts well the angle. I suspect there is something broken in the calculation of the final move vector, but since it is simple trigonometry, I believe I setted it up correctly.
I would gladly accept any tips on what might be wrong.
How does it look like: (the godot icon should follow the player)
Here is my ghost code:
extends KinematicBody2D
var reached = false
const SPEED = 1
const ROTATION_SPEED = 20
func _ready():
set_process(true)
pass
func _process(delta):
var ang = get_angle_to(get_node("../player").get_pos())
rotate(ang*ROTATION_SPEED*delta)
var x = cos(ang)
var y = -sin(ang)
if !reached:
move(Vector2(x*SPEED,y*SPEED))
func _on_player_body_enter( body ):
reached = true
func _on_player_body_exit( body ):
reached = false
the final vector of the ghost (/ kinematicbody2D) is always 1 on x. how so?