How to move a KinematicBody2D on collision?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Shadow Assassin

I’m new to programming and GDscript. I have 2 kinematicbody 1 player and 1 ball I want the ball to start stationary and move when the player collides with the ball at a set velocity but I don’t know how to set the ball script to do this? I think it is basic but so far haven’t found anything.

Ball script:
extends KinematicBody2D

var velocity = Vector2(100, 100)

func _physics_process(delta):
var collision_info = move_and_collide(velocity * delta)
if collision_info:
velocity = velocity.bounce(collision_info.normal)

Player script:
extends KinematicBody2D

var speed = 250
var velocity = Vector2()
var use_slide = true

func get_input():
velocity = Vector2()
if Input.is_action_pressed(‘ui_right’):
velocity.x += 1
if Input.is_action_pressed(‘ui_left’):
velocity.x -= 1
if Input.is_action_pressed(‘ui_down’):
velocity.y += 1
if Input.is_action_pressed(‘ui_up’):
velocity.y -= 1
velocity = velocity.normalized() * speed

func _physics_process(delta):
get_input()
if use_slide:
move_and_slide(velocity)
else:
move_and_slide(velocity * delta)