Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Beizey |
{enter code here**extends KinematicBody2D
const ball_scene = preload(“res://mini scenes/ball.tscn”)
func _ready():
set_physics_process(true)
set_process_input(true)
func _physics_process(_delta):
var y = get_position().y
var mouse_x = get_viewport().get_mouse_position().x
set_position(Vector2(mouse_x, y))
func _input(event):
if event is InputEvent.MOUSE_BUTTON && event.is_action_pressed():
var ball = ball_scene.instance()
ball.set_position(get_position() - Vector2(0, 16))
get_tree().get_root.add_child(ball)
}