creating an alternative to box collider 2d question
So I am new to unity and I am working on the Ruby's Adventure: 2D Beginner learning project to learn the unity 2d basics. My computer is starting to get pretty old so needless to say there is definitely some lag here and there.
.
.
In the project, we set the movement for each axis to move in terms of real time instead of frames. In case I am not explaining it well enough, the line of code looks something like this where someUserInput() returns either 1, 0, or -1:
position.x = position.x + speed * Time.deltaTime \* someUserInput();
.
.
The problem with this is that the position.x does not change linearly per frame if lag is present. This becomes an issue with box collider 2d because in these periods of lag, my character passes straight through the box collider border and ends up walking on water zones. I was wondering if it would be better to create a separate script and function that would prevent the character from ever having their position equal to the coordinates inside the barrier zones. so something similar to this:
v
oid BarrierZone(float x1, float y1, float x2, float y2)
{
if((character.position.x >= x1 && character.position.y >= y1) && (character.position.x <= x2 && character.position.y <= y2))
{
DoNotUpdateCharacterPosition();
}
}
.
.
I guess the questions I am asking are: are there any drawbacks of doing it this way? Does unity already offer something like this? Does this method require significantly more computational power than box collider? Are there better ways of doing this? And finally, is this method or similar methods realistic?
Your answer
![](https://koobas.hobune.stream/wayback/20220612202514im_/https://answers.unity.com/themes/thub/images/avi.jpg)