Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

why is my paddle going through the walls

Discussion in 'Scripting' started by isanvel, Jul 29, 2019.

  1. isanvel

    isanvel

    Joined:
    Mar 21, 2019
    Posts:
    15
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    4,558
    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:

    Code (csharp):
    1. transform.position = new Vector3( transform.position.x, limitYPos, transform.position.z);
    to put the new limited clamped value back.
     
  3. isanvel

    isanvel

    Joined:
    Mar 21, 2019
    Posts:
    15
    i tried that but the paddle still goes over the wall
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    4,558
    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()
     
  5. isanvel

    isanvel

    Joined:
    Mar 21, 2019
    Posts:
    15
    i did Debug.log(limitYPos)
    and all i see is this

     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    4,558
    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().
     
  7. isanvel

    isanvel

    Joined:
    Mar 21, 2019
    Posts:
    15
    yes i forgot to put it in update my bad

     
  8. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    4,558
    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.