This week I am working a breakout type game and things are progressing nicely, however I have run into an issue with moving the paddle with the mouse on the y axis, while keeping the value of y and z the same. Currently I am attempting to do it like this
Vector3 newLocation = new Vector3(Input.mousePosition.x, transform.position.y, transform.position.z);
transform.position = newLocation;
I have also tried to translate the position, but in both cases the mouse shoots off into the middle of nowhere. I would also like the mouse point to center, and disappear, but that is not as important. Any suggestions?
Did you mean moving on the x axis? Here is one of my testing script in C#. This script moves on the x-axis.
void Update ()
{
transform.position = new Vector3((Input.mousePosition.x / 20), 0, 0);
if (Input.GetMouseButtonDown(0))
{
Instantiate(this.bullet, transform.position + new Vector3(0, 3, 0), Quaternion.identity);
}
}
I base all my game objects in the first quadrant with the original (0,0,0). I suggest that you test your new location by setting some axises with a zero. For example,
Vector3 newLocation = new Vector3(Input.mousePosition.x, 0, 0);
and also make sure that you set your main camera to look at this position (paddle).