Vector2 Being Set To Zero After Multiplying By Time.deltatime

Quick bit of context:
Whenever the player touches the left wall they just freeze and are unable to move. This is due to when the Vector2 tmp is multiplied by Time.deltaTime it suddenly becomes (0,0)
Image of defect:
4428769--404581--upload_2019-4-14_23-4-32.png
This only happens on left walls. The ceiling, floor, and right walls all function as intended.
Logs:

         if (isGrounded())
        {
            MovementVector.x = Mathf.MoveTowards(previousMovementVector.x, speed * MovementVector.x, acceleration) ;
            if (MovementVector.y == 1)
            {
                MovementVector.y = jumpheight;
                inputComplete = true;
            } else if (inputComplete == false)
            {
                MovementVector.y = jumpheight;
                inputComplete = true;
            }
        } else
        {
            Debug.Log("Pre horizontal: " + MovementVector);
            MovementVector.x = Mathf.MoveTowards(previousMovementVector.x, speed * MovementVector.x, acceleration * (airInfluence / 100) );
            Debug.Log("Pre prevoismove: " + MovementVector);
            MovementVector.y = previousMovementVector.y;
            Debug.Log("Pre gravity: " + MovementVector);
            MovementVector.y -= gravity;
        }
        Debug.Log("Pre correctMovement: " + MovementVector);
        MovementVector = CorrectMovemet(MovementVector);
        Debug.Log("operator test: " + MovementVector * Time.deltaTime);
        rb.position = rb.position + MovementVector * Time.deltaTime;
        previousMovementVector = MovementVector;
    }

    private Vector2 CorrectMovemet(Vector2 movementVector)
    {
        Debug.Log("Pre correctMovement2: " + movementVector + " Time.deltaTime" + Time.deltaTime + " combined: " + new Vector2(movementVector.x * Time.deltaTime, movementVector.y * Time.deltaTime) + "components: " + movementVector.x + " " +movementVector.y);
        Debug.Log("Expected new vector: " + movementVector.x * Time.deltaTime + " " + movementVector.y * Time.deltaTime);
        Vector2 tmp = movementVector;// * Time.deltaTime;
        Debug.Log("tmp: " + tmp);
        tmp *= Time.deltaTime;
        Debug.Log("tmp2: " + tmp);
        movementVector *= Time.deltaTime;
        RaycastHit2D hit = Physics2D.BoxCast(rb.position, new Vector2(0.5f, 1), 0, movementVector, movementVector.magnitude, GroundLayer);
        if (Physics2D.BoxCast(transform.position, new Vector2(0.5f, 1), 0, movementVector, movementVector.magnitude, GroundLayer))
        {
            Debug.Log("tmp :" + tmp + "Collision: " + hit.point + " center:  " + hit.centroid + "Normal:" + hit.normal + "Result:" + ((hit.centroid - rb.position) / Time.deltaTime) + "is grounded?" + isGrounded() + "rb.position" + rb.position);
            return ((hit.centroid - rb.position) / Time.deltaTime);

        }
        else
        {
            return movementVector / Time.deltaTime;
        }
    }

Didn’t read the code, but I’m betting it doesn’t become 0.

Debug.Log a Vector2 only shows one decimal and Time.deltaTime is typically something like 0.017, so Debug Log shows it as zero, but it doesn’t mean it is.

You can say .ToString(“Fx”) on the float, x is the number of decimal points you want.

1 Like