When the ball collides with the apex of the player's rectangle, the player begins to move along with the ball
I found no method to detect whether the collision was at the apex of the rectangle Script Ball
var posicaoInit
var velocity
const SPEED= 500
func _ready():
posicaoInit =position
velocity=Vector2(1,-1)
func _physics_process(delta):
var collision = move_and_collide(velocidade*delta*SPEED)
if collision :
velocity=velocity.bounce(collision.get_normal())
Script Player
const SPEED = 300.0
const JUMP_VELOCITY = -500.0
func _physics_process(delta):
# Add the gravity.
velocity.x=0
velocity.y += gravity * delta
move_and_slide()
func _on_touch_1_pressed():
velocity.y=JUMP_VELOCITY
Script Game
extends Node2D
var Player1Score = 0
var Player2Score = 0
func _on_wall_left_body_entered(body):
$Boll.position = Vector2(576,324)
Player2Score+=1
func _on_wall_right_body_entered(body):
$Boll.position = Vector2(576,324)
Player1Score+=1
func _process(delta):
$Pontuacao_1.text= str(Player1Score)
$Pontuacao_2.text =str(Player2Score)