- Home /
Weird Collisions Between Paddle and Ball (Breakout)
So, I'm trying to put a Breakout minigame in my game, but I ran into this weird problem: The game starts, my ball goes up, as intended, bounces off the first brick and when i try to catch it with my paddle, the ball simply changes its trajectory to be parallel to my paddle. I'm terrible with code, the one I wrote I did following a tutorial I found on the internet. I'll Ilustrate the problem in image. Here's the link to the image
And these are the codes for my paddle and the ball:
public class YPaddleBreakoutNOVO : MonoBehaviour
{
//velocidade de movimento
public float m_Speed = 20.0f;
private Rigidbody m_Body;
private void Start()
{
m_Body = GetComponent<Rigidbody>();
//Cursor.visible = false;
}
private void FixedUpdate()
{
//Recebe entrada das setas (vou tentar mudar pro mouse)
float horizontal = Input.GetAxis("Horizontal");
//cria vetor aplicando a entrada no eixo X
Vector3 movement = Vector3.zero;
movement.x = horizontal * m_Speed * Time.deltaTime;
//move o corpo rigido com o vetor de entrada
m_Body.MovePosition(m_Body.transform.position + movement);
}
}
and the ball:
public class YBreakoutBallNOVO : MonoBehaviour
{
//força inicial da bola
public float m_Force = 1000.0f;
//referencia rigidbody
private Rigidbody m_Body;
private void Start()
{
m_Body = GetComponent<Rigidbody>();
//define direção incial em Y
Vector3 direction = Vector3.up;
//sorteia o valor de X pra criar um angulo pra frente
direction.x = Random.Range(-0.8f, 0.8f);
//direction = Vector3.Reflect(raquete.position, Vector3.up);
//bota força na bola
m_Body.AddForce(direction * m_Force);
}
}
The scene where the minigame is located is a 3D scene, the entire scene is standing (walls go up on the Y axis). Would really appreciate some help!
Your answer
Follow this Question
Related Questions
Unity3D: Get Velocity after collision 0 Answers
Sider Joint 2D in 3D 0 Answers
Change direction of ball based on where it hits paddle -- 3d breakout game 0 Answers
Player getting stuck in ground (3D) player has Rigidbody, and Box Collider, world is Mesh Colliders 0 Answers
How to stop sphere from clipping through cube edges aside from lowering Time.FixedDeltaTime? 1 Answer