The old question seems outdated. I ask a new one
This the Player Bullet's Code

``````extends KinematicBody2D
var pos=Vector2.ZERO
func _physics_process(delta):
rotation=GV.PlayerBullet.position.angle_to_point(position)
pos-=(position-GV.PlayerBullet.position)/1000000
pos=pos.ceil()
position=pos
``````

it goes in hexagon line, not straight line. and get slower too because of closer distance

in Engine

Hi,
when moving a KinematicBody2D it's not good practice to set the position directly, rather you should use moveandslide or moveandcollide so you get the benefit of the collision detection.

There is an intro tutorial here

In your case you could do something like this

``````extends KinematicBody2D

var speed = 10

func _physics_process(delta):
var vec_to_player = (GV.PlayerBullet.position - position).normalized()
rotation = vec_to_player.angle()
var collision = move_and_collide( vec_to_player * speed)
if collision:
print("Collided with ", collision.collider.name)
``````

This calculates the vector from player and normalizes it, so that gives you a direction.
Then, from that direction you can set your rotation.
Multiply that vector by the speed to get a scaled velocity vector, and call moveandcollide
This will return a collision object if it collided, which you need to handle

I don't know how your game will work, however this model will update the direction if the GV.PlayerBullet.position moves. If that's not what you want, you need to store the vectoplayer and not update it each frame. Also, you might prefer moveandslide to moveandcollide depending on your design. Check out the tutorial above for advice.

by (541 points)
selected by

It worked for me, thanks