A Unity ID allows you to buy and/or subscribe to Unity products and services, shop in the Asset Store and participate
in the Unity community.
Discussion in 'Scripting' started by isanvel, Jul 29, 2019.
this is my script, i used a clamp but it is going through the walls
Your limit code is applying the limit, then overwriting it with the transform.position.y (lines 44 and 45).
Also, note that you will not be able to assign to the .y property of a transform.position.
Instead you want to do:
transform.position = new Vector3( transform.position.x, limitYPos, transform.position.z);
to put the new limited clamped value back.
i tried that but the paddle still goes over the wall
Time to start debugging! We know that Mathf.Clamp() works. Therefore, start figuring out what you are feeding it and what it is returning, and what you are doing with what returns from it. Either attach the debugger or else spit some data out with Debug.Log()
i did Debug.log(limitYPos)
and all i see is this
You get one line of output? Shouldn't you expect that code to run every frame?? Check where you are calling the limit code... maybe it is in Start() instead of Update().
yes i forgot to put it in update my bad
Excellent! Easy mistake, I do it all the time. That's why putting in a few Debug.Log() statements will almost always give you (at least) some more information about what's going on.