I am trying to make an moving ball however its hard.
Here is my code:
local briques = createGameBoard()
while true do
if ball.Position.Z > gameBoard.bounds["left bound"].Position.Z then
ball.Position += Vector3.new(1, 0, 0)
elseif ball.Position.Z > gameBoard.bounds["right bound"].Position.Z then
ball.Position -= Vector3.new(1, 0, 0)
end
wait(0.1)
end
It’s supposed to bounce the ball once its reaching one of the boundaries wall and when it touche the paddle(raquette) and when it touches an brick
Then you may be able to use Magnitude to find the distance between the objects as well, The ball’s position - The outer bounds, correct? and you may want to use TweenService instead of just moving the ball instantly If i’m thinking of the game that you are going for accurately.
Also whenever it would hit the borders wouldn’t it go down/up there would be some math included to find out which direction it needs to travel if it’s coming from below and going up or going from above and going down when it hit a brick and then hits the wall.
The problem with the .Touched Solution is that it require the part to be colliding with other parts. To collide with other part it require the ball to be welded or anchored to other parts.
you are basically asking how do i make a very simple physics engine. just have the ball move every frame based on a velocity and have the velocity change upon collision, reflecting it across the surface it touched