- Home /
True and false work weird?
I want my Oject to move up when it collides with "Player" ( "Player" standing on the Object, I want to make an elevator) so I write the code like in the picture. However, It works really weird. When "Player" Collide with Object, The Objet goes up but the Debug.log keeps spamming. And when the "Player" jump off, The Object also keep going up ,the Debug.log is spamming. I have no idea what is happening. One thing I notice that when "Player" is colliding with the Objet, the Debug.log spam slower.
Answer by adscott1982 · May 24, 2021 at 01:51 PM
When the player jumps off 'goup' is set to false and stays false. So the debug log will message "player go off" 50 times a second. This is because FixedUpdate is run 50 times a second.
It keeps going up because you don't set the velocity back to zero on collision exit, or alternatively in in the 'if (goup == false)' code block. The velocity is still set to go up until you tell it to stop.
ahhhh i see, Thank youuuu soo much, And one more thing I want to ask. When "goup" is TRUE, the Debug Log is still spam$$anonymous$$g. Do you know why? I still don't know that part.
The only debug logging in your screenshot is for when 'goup' is false. I expect you have some other debug logging elsewhere in your code that is being hit.
If you check the message text of the logs that are spam$$anonymous$$g, you can search for that text in your code and find it.
You can then attach the debugger at runtime and when you want to put in a breakpoint on the Debug.Log line to see what is happening with your variables at the time to work out why the log message is getting displayed.