So the title pretty much covers the whole issue, when I go to move the paddle with the mouse they wont stick together. There is always a gap between them what’s weird though is when looking at the mouse position through debug.log it comes up the same as the paddle transform position which can’t be right right?. I made the game in 2D first and didn’t have this issue before but now im having trouble making it in 3D.
I left the code the same as in the 2D course for this post but the things i’ve tried to make work are, using “screentoworldpoint” , “transform.transformpoint”. Little to zero knowledge on what either of those two things did.
Pictures
Code
Summary
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Paddle : MonoBehaviour
{
[SerializeField] float ScreenWidthInUnits = 16f;
[SerializeField] float xMin = 1f, xMax = 15f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
Paddle_Movement();
}
public void Paddle_Movement()
{
Debug.Log(Input.mousePosition.x / Screen.width * ScreenWidthInUnits);
float PaddlePositionX_Axis = Input.mousePosition.x / Screen.width * ScreenWidthInUnits;
Vector3 PaddlePosition = new Vector3(transform.position.x, transform.position.y, transform.position.z);
PaddlePosition.x = Mathf.Clamp(PaddlePositionX_Axis, xMin, xMax);
transform.position = PaddlePosition;
}
}
Edit: I am very lost because no matter what I tried it felt like the distance between the mouse and paddle wasn’t shortening and the only thing that was happening when changing the code around was the paddle would slow down / go faster.