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 physicsprocess(delta):
var collisioninfo = moveandcollide(velocity * delta)
if collisioninfo:
velocity = velocity.bounce(collision_info.normal)
Player script:
extends KinematicBody2D
var speed = 250
var velocity = Vector2()
var use_slide = true
func getinput():
velocity = Vector2()
if Input.isactionpressed('uiright'):
velocity.x += 1
if Input.isactionpressed('uileft'):
velocity.x -= 1
if Input.isactionpressed('uidown'):
velocity.y += 1
if Input.isactionpressed('ui_up'):
velocity.y -= 1
velocity = velocity.normalized() * speed
func physicsprocess(delta):
getinput()
if useslide:
moveandslide(velocity)
else:
moveandslide(velocity * delta)