Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends KinematicBody2D
- export var speed = 300
- var velocity = Vector2(0, 0)
- var click_position = Vector2(0, 0)
- func _ready():
- # Set the click position to the player's current position
- click_position = Vector2(position.x, position.y)
- func _physics_process(delta):
- # This input will need to be created in the input map
- if Input.is_action_just_pressed("left_click"):
- click_position = get_global_mouse_position()
- # Calculate the target position
- var target_position = (click_position - position).normalized()
- # Check if the player is in a 3px range of the click position, if not move to the target position
- if position.distance_to(click_position) > 3:
- move_and_slide(target_position * speed)
- look_at(click_position)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement