Paddle sticks out of play space and doesn't move

this is my code but the paddle just sticks at left side of the screen and it doesn’t move Is there
something wrong with my code?
void Update () {
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;



}

i would start be adjusting your code to the following:

void Update () {

    Vector3 paddlepos = new Vector3 (0.5f, this.transform.position.y, 0f);
    float mousePosInBlocks = Input.mousePosition.x / Screen.width * 16;

    Debug.Log("I am: "+this.gameObject.name+
              "\nScreen Width is: "+Screen.width   
              "\nMouse x Position is: "+ Input.mousePosition.x
              "\nMouse Position is: "+mousePosInBlocks
              "\nPaddle position is: "+paddlepos);

    paddlepos.x = Mathf.Clamp (mousePosInBlocks, 0.5f, 15.5f);
    this.transform.position = paddlepos;
    Debug.Log("Final position :"+this.transform.position);
 }

Do the debugging statements output what you would expect to see? If you take the outputs and hand calculate them do you get the same final position?

1 Like

what is the meaning of this part?

Debug.Log("I am: “+this.gameObject.name+
”\nScreen Width is: “+Screen.width
”\nMouse x Position is: “+ Input.mousePosition.x
”\nMouse Position is: “+mousePosInBlocks
”\nPaddle position is: "+paddlepos);

and my unity version is 4.7.2

It’s the same as "Debug.Log(“Hello world”); or even Print(“Hello world”);

I just outputs to the console some details for you to check that your variables are set correctly as you would expect them to be.

1 Like

thanks and I think you for got to put + at the debug .log
but you solved my problem thank you :grin:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms