Hi,
Not sure if i’m missing something, but this script doesn’t seem to stick the ball to the paddle on the Y axis, only the X axis ?
With the script below the ball stays at the height where I placed it, but does follow the paddle on X axis.
How would you make it stick to the paddle on Y axis as well ?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Ball : MonoBehaviour
{
// config params
[SerializeField] Paddle paddle1;
// state
Vector2 paddleToBallVector;
// Use this for initialization
void Start()
{
paddleToBallVector = transform.position - paddle1.transform.position;
}
// Update is called once per frame
void Update()
{
Vector2 paddlePos = new Vector2(paddle1.transform.position.x, paddle1.transform.position.y);
transform.position = paddlePos + paddleToBallVector;
}
}