79781003

Date: 2025-10-02 14:21:41
Score: 0.5
Natty:
Report link

Solved by adding saving the last position:

private Vector2 lastPos;

private void FixedUpdate()
{
    Vector2 v = rb.linearVelocity;
    Vector2 pos = rb.position;

    if (fixation.up && v.y > 0)
    {
        v.y = 0;
        pos.y = lastPos.y;
    }
    if (fixation.down && v.y < 0)
    {
        v.y = 0;
        pos.y = lastPos.y;
    }
    if (fixation.left && v.x < 0)
    {
        v.x = 0;
        pos.x = lastPos.x;
    }
    if (fixation.right && v.x > 0)
    {
        v.x = 0;
        pos.x = lastPos.x;
    }

    rb.linearVelocity = v;
    rb.position = pos;

    lastPos = rb.position;
}
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: PinBIb