Question by
Dtained · Sep 21, 2020 at 10:01 PM ·
cameravector3camera-movementoffsetif statement
Vector3 is increasing infinitely instead of capping at the if statement limit,Doing a smooth move for a camera but it continues to pan even though it reaches it's x and y offset
So just started C# yesterday and I have a project where the player is a cube dodging other cubes. It's from Brackey's tutorial, so most of my learning has been from there. I want the cube to hit a boudry and start moving backwards, which I've achieved. I also wasn't the camera Offset to increase from 2 to 7, but it ignores the boundary. Keep in mind the code is messy and probably inefficient because I've virtually a novice at this stuff. Here is the code:
if (PlayerCollision.ReverseMode && !(cameraupdated))
{
Vector3 offsetedit = Offset;
if (offsetedit.y != 7.0)
{
offsetedit.y += 0.01f;
Offset = offsetedit;
Debug.Log(Offset);
if (offsetedit.y == 7)
{
cameraupdatedz = true;
}
}
if (offsetedit.z != -16.0)
{
offsetedit.z -= 0.01f;
Offset = offsetedit;
if (offsetedit.z == -21)
{
cameraupdatedz = true;
}
}
if (cameraupdatedy && cameraupdatedz)
{
cameraupdated = true;
}
}
Comment
@Dtained Floating point values rarely match exact values in practice ( != 7, != -16). Try using less/more than instead.