Here is the code:

extends KinematicBody2D

var is_dragging = false
var touchpos = 0


func _input(event):
    if event is InputEventMouseButton:
        if event.is_pressed():
            is_dragging = true
        else:
            is_dragging = false
    if is_dragging:
        touchpos = event.position

func _physics_process(_delta):
    if is_dragging:
        touchpos.x = 70
          $Sprite.global_position = touchpos

I was expecting the Ball to bounce on the paddle but it was passing through it as only Sprite was moving. Not the kinematicBody2D. So, can anyone tell me how to do that?

1

There are 1 best solutions below

0
On BEST ANSWER

You basically answered it yourself. Your code only changes the position of your sprite, not the position of your kinematicbody.

Change:

$Sprite.global_position = touchpos

to

global_position = touchpos

This will move rhe whole body with all their children.