Hi all, at first my cursor was aligned perfectly with my paddle and everything was working fine, up until Section 5 Lesson 92. You can even notice the issue within the first 15 seconds of Lesson 92’s video. When and the paddle is in the center of the screen the mouse will be aligned in the center of the paddle, then when you move the paddle to the left and right you can see the cursor will move further away from the paddle and no longer be aligned with it.
Here is a link to the lecture to see the issue in the first 15 seconds of the video https://www.udemy.com/unitycourse/learn/v4/t/lecture/2073248
I have no idea what could have broken and caused this issue, does anyone know how I can fix it? Here is my code for the paddle.
EDIT:
So I went backtracking in the video Lectures and noticed that the issue does not occur in the beginning of Lecture 87, but it does occur in the beginning of Lecture 88. Perhaps it was introduced in Lecture 87 somehow? I will do some more investigation.
using UnityEngine;
using System.Collections;
public class Paddle : MonoBehaviour {
public bool autoPlay = false;
private Ball ball;
void Start () {
ball = GameObject.FindObjectOfType<Ball>();
}
// Update is called once per frame
void Update () {
if (autoPlay == false) {
MoveWithMouse();
} else {
AutoPlay();
}
}
void AutoPlay () {
Vector3 paddlePos = new Vector3 (0.5f, this.transform.position.y, 0f);
Vector3 ballPos = ball.transform.position;
paddlePos.x = Mathf.Clamp(ballPos.x, 0.5f, 15.5f);
this.transform.position = paddlePos;
}
void MoveWithMouse () {
Vector3 paddlePos = new Vector3 (0.5f, this.transform.position.y, 0f);
float mousePosInBlocks = Input.mousePosition.x / Screen.width * 16;
paddlePos.x = Mathf.Clamp(mousePosInBlocks, 0.5f, 15.5f);
this.transform.position = paddlePos;
}
}
Any help would be highly appreciated, thank you! happy coding.