Advertisement
metalx1000

Godot Follow Mouse

Sep 18th, 2021
3,417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extends KinematicBody2D
  2.  
  3. export (int) var speed = 500
  4.  
  5. var target = Vector2()
  6. var velocity = Vector2()
  7.  
  8. func _physics_process(delta):
  9.     target = get_global_mouse_position()
  10.     velocity = position.direction_to(target) * speed
  11.     look_at(target)
  12.     if position.distance_to(target) > 5:
  13.         velocity = move_and_slide(velocity)
  14.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement