Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags
(+1)

Interesting. Where’d you put the code that handled the .1 => 1 pixel code? It works nicely. I like ray-casting. It gives me a nice sense of satisfaction when I get it working.

I ended up adding a child GameObject that held the sprite and animator (in my case). The parent object has the collider and rigidbody. I let the physics engine move the overall object. The child object that renders the sprite would then round the parent’s position and set its own position accordingly. The collider is a factional pixel off, but that was fine for my needs.

    void Update()
    {
        if (SnapToPixel)
        {
            Vector3 roundedPos = transform.parent.position;
            roundedPos.x = Mathf.Floor(roundedPos.x);
            roundedPos.y = Mathf.Floor(roundedPos.y);
            SpriteRenderer.transform.position = roundedPos;
        }

    }

Mine was set up very similar! but I moved the parent, and rotated/offset the child on certain surfaces.

Think I used pixels per unit = 10 on everything, that gave 0.1 world space per pixel. I should have used per unit = 1 thinking about it... -_- much easier to round everything to an integer than to 0.1 ,':/

When moving the slug pixel by pixel, I didn't use a force to move, I used transform.position to move by a pixel (0.1) in whatever direction. Only the jump used 2Drigidboyd forces, then when the collision happened i'd snap back to nearest pixel, and move using transform.position again.

honestly if i'd have used pixel per unit = 1 I may have been able to use your code and simplify my problems a lot..

(+1)

Ja, I was at a pixel per unit. I didn’t do that intentionally in the beginning, but it worked out nice and saved me a bunch of time. Thanks for answering.

I was playing Slug in Heat again this morning. Very neat idea. There are so many little things to pick up from jam entries to store away for inspiration.