0 votes

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 collision
info:
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.is
actionpressed('uiright'):
velocity.x += 1
if Input.isactionpressed('uileft'):
velocity.x -= 1
if Input.is
actionpressed('uidown'):
velocity.y += 1
if Input.isactionpressed('ui_up'):
velocity.y -= 1
velocity = velocity.normalized() * speed

func physicsprocess(delta):
getinput()
if use
slide:
moveandslide(velocity)
else:
moveandslide(velocity * delta)

in Engine by (20 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.