![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Aljabri-Salman |
I am new to godot and have been trying to practice by creating something similar to snooker game. I was able to code the collision between the cue ball and the walls but I am not able to do collisions between other target balls. Basically how would you do the collision for snooker game?
my code so far for the cue ball:
extends KinematicBody2D
var velocity = Vector2()
var collision
func _ready() -> void:
pass # Replace with function body.
func _physics_process(delta: float) -> void:
velocity.x = lerp(velocity.x, 0.0, 0.1)
velocity.y = lerp(velocity.y, 0.0, .1)
if collision:
velocity = velocity.bounce(collision.normal)
collision = move_and_collide(velocity)
func _input(event: InputEvent) -> void:
if event is InputEventMouseButton and event.pressed:
velocity.x = 70
velocity.y = -60
collision = move_and_collide(velocity)
How to calculate the bounce velocity if a ball is moving and the other is stationery and how to do if they both are moving.?