I created a GameObject that can travel in the main scene. I implemented a code restricting it’s movement so it wont go outside of the boundaries. To make better readability i did:
float posY = transform.position.y;
and so on. But when I started the game whenever character reached the boundaries and would try to move simultanously on x and y axis it would get slowed down significantly because there was some “bumping” happening;
But when I did it likle that:
if(transform.position.y < -4.38f) {
transform.position = new Vector3(transform.position.x, -4.38f, 0);
} else if (transform.position.y > 0) {
transform.position = new Vector3(transform.position.x, 0, 0);
}
if(transform.position.x > 6.25f) {
transform.position = new Vector3(6.25f, transform.position.y, 0);
} else if (transform.position.x < -6.25f) {
transform.position = new Vector3(-6.25f, transform.position.y, 0);
}
The performance seem to be good, there is no bumping and character is not slowed down when it’s trying to go outside of the boundaries.
So my question is:
Is assigning position (and different things like that, I’m a beginner co can’t think of anything more right now) really affects performance?