r/Unity2D • • Feb 28 '26

Has anyone had this problem when designing their platformer? What are the best solutions?

Post image
864 Upvotes

128 comments sorted by

67

u/OneMoreName1 Feb 28 '26

Looks like you should calculate the dot product between the ground detection and the "ground", and if its too steep dont allow jumping

10

u/Elesh_N Feb 28 '26

This is actually my current approach, but in unity your colliders can bleed together a little bit so I still get the very occasional wall jump, and it can also get a bit jank in corners or in places where two different platforms meet.

1

u/UtmostBroken Mar 01 '26

For my platformers, I had left-wall and right-wall detection. You want these wall detections to be a bit higher than the actual ground detection and they should cover the entire height of the player. I also made the ground detection larger than the bottom's width. Now, if right-wall is detected and you are on the ground, you can't move right. Same goes for left-side if left-wall is detected. By the way, the reason the ground detection is larger than the collider, is because when you are right up against a wall, but you can jump onto it: You want the ground detection to activate while the wall detection deactivates, which lets you move onto the wall. Perfect for a blocky staircase. Also, when the player begins to move, if the y-velocity is above 0, I usually set it to 0.

All of this depends on how "snappy" or "loose" you want your player controller to be. I would highly recommend adding coyote time to your game if you have not already.

130

u/ForlornMemory Feb 28 '26

I'm pretty sure you can avoid using bottom collider and instead use a tiny raycast. Calculating a whole box is kind of expensive, isn't it? I made a short platformer using that and also side detectors for wall jumps, worked pretty good. You can check it out here: https://memorydreams.itch.io/microvania

4

u/Elesh_N Feb 28 '26

I use downward raycasts right now, this is just a more comprehensive visual. The raycasts are functionally the sides of the box in the image.

1

u/RewRose Mar 01 '26

So you use two rays - one on each edge ?

Or is it three with one in the middle of the box too ?

1

u/ForlornMemory Mar 04 '26

You know, I think I remember how I dealt with that problem in my game. You need to prevent the player from jumping when falling, not from jumping when they have no ground underneath. What it means is that you simply have to find some other way to check if your player is falling or not. I think in my game I did it by checking the vertical velocity changes along with ground detection. So basically I had a state system with airborne and on-ground states. You turn airborne when you leave the ground and your vertical velocity changes, and you turn on-ground when your feet touch the ground.

43

u/DerekSturm Feb 28 '26

The issue with a raycast comes up when you're standing in the middle of two blocks with a tiny gap in the middle. You're still standing and should definitely be able to jump, but the raycast won't hit anything.

32

u/TheLowestAnimal Feb 28 '26

I was told in the past you need to run multiple. Like 3 or something

0

u/[deleted] Feb 28 '26

[deleted]

23

u/FaolanBaelfire Feb 28 '26

That's why you conditionally check each one as opposed to grouping them and checking them all as true or false.

One ray cast can be true. Another cast can be false.

A box collider can be only one or the other for the entirety of it's size

13

u/Jerovil42 Feb 28 '26

Way cheaper

3

u/AbdullahMRiad Mar 01 '26

this is more precise though allowing for easier implementation of coyote time for example

17

u/oddbawlstudios Feb 28 '26

Typically its 3 raycasts, 1 on each edge and 1 in the middle.

1

u/Luccacalu Mar 01 '26

what's the purpose of the one in the middle?

3

u/oddbawlstudios Mar 01 '26

If you're on a thin platform where the two rays on the ends cannot detect anything.

4

u/Luccacalu Mar 01 '26

ohhhhhhhh, fair enough

But what if there's an ever thinner platform that's between the middle and the other ray? I believe there must be a way to check the normal under the entirety of the object, no? Without depending on specified points

6

u/BrawnoldMcScrawnold Mar 01 '26

Generally in dev you want to follow KISS. Keep It Simple Stupid. If you dont need it, don't build it. Im sure you could cast 11 different raycasts under a character to make sure that the smallest platforms dont slip through the cracks. But consider Mario, there literally ISNT a platform in the game that is smaller than a third of his width, so the 3 raycasts solutions is good enough. As the conditions start expanding, however, so do your checks.

1

u/Luccacalu Mar 02 '26

Yeah, I agree, at this point it's more of a thought experiment

If I were building a game where platforms could be of any width (even a single pixel), what you think would be the best solution?

1

u/1cec0ld Mar 02 '26

Probably have to calculate a whole box, as the OP is indicating. At that point you just have to eat the risks of their two possibilities. And also have very odd visuals as your character hovers with a pixel pointing up at their crotch.

1

u/[deleted] Mar 04 '26

implement a gore system that cuts mario in half if he lands on a platform thin enough

1

u/jort93 Mar 03 '26

It would need to be smaller than half the width, not one third. Classic Fence post problem. The distance between rays is 0.5.

1

u/BrawnoldMcScrawnold Mar 03 '26

You are right, thats my bad... though the point still stands. I dont think mario has a platform that small compared to him.

2

u/oddbawlstudios Mar 01 '26

Realistically speaking, at that point you might want to invest in another method, like checking the y velocity of the player.

1

u/jort93 Mar 03 '26

Don't put a platform in your game that's less than half width of the player character lol.

1

u/Luccacalu Mar 03 '26

What if it's a needle pointing up while the player is invulnerable

1

u/oddbawlstudios Mar 03 '26

Typically if its like spikes, there's a whole hitbox. But again, if people are this concerned, just check the y velocity to see if its 0, that'll mean the player isn't falling or jumping.

1

u/Luccacalu Mar 03 '26

But the point which the player is starting to fall the y velocity also gets close to (turning negative to positive), which would allow for a very small window where the player could double jump infinitely

As for the game design part, I imagine something like the player being a square that is affected by rotation, so when it's over a spike it kinda starts rotating to the side (so, a square hitbox wouldn't work), but you could still jump if standing over said spike

→ More replies (0)

8

u/wisegod62 Just Starting Feb 28 '26

something I do is use two - a down left and a down right.

2

u/stalebubbletea Mar 01 '26

You can do a boxcast instead of a raycast

15

u/intelligent_rat Mar 01 '26

In the grand scheme of things, calculating AABB collision between boxes is not expensive at all

13

u/Zanthous Intermediate Mar 01 '26

A single box overlap is not expensive. This shouldn't be upvoted.

To OP - you can do raycasts - mulitple, and you can also check the normals of what gets hit. If you understand how to use the normal vectors, raycasts, collider overlaps, shapecasts, you will be able to iterate and work through most problems tiy gave

26

u/lukinatorYT Feb 28 '26

I usually just add a timer that starts counting once the player loses contact to the ground. I then only disable jumping once the timer has been running for more than a few milliseconds

4

u/Elesh_N Feb 28 '26

I use this, but if you land in a spot like you are in the left pic you're out of luck.

1

u/[deleted] Mar 01 '26

[removed] — view removed comment

3

u/IMightBeAHamster Mar 01 '26

Depends how forgiving you want your game to be. Celeste famously allows you to do a bunch of stuff you "shouldn't" be capable of for the sake of making the game feel fair, that when you die it was definitely your fault and not the game arbitrarily deciding you failed.

2

u/supamario132 Mar 01 '26

What if you're not running? You could fall exactly on that spot from above and then be unable to jump while statically sitting there

28

u/CrimsonChinotto Feb 28 '26

This is called Coyote Timer!

4

u/snlehton Mar 01 '26

Few milliseconds is way too little. At 60 FPS, even single frame lasts for over 16 milliseconds. I've used something like 100 to 200 ms in the past with good results.

150

u/GigaTerra Feb 28 '26

This problem is commonly solved with a shape cast and checking the normal direction, Unity has an old character controller that teaches you exactly how to avoid this. https://youtu.be/wGI2e3Dzk_w?si=H6a8KFJ9ycjFnRr6

This is an old tutorial but the controller is even older, it is what a lot of 2D platformers used and still use, it is a solid foundational controller to start with.

9

u/NeoChrisOmega Feb 28 '26

Not the best solution, but I tend to teach kids, so I find a lot of quick and easy solutions.

If you add a 2D Physics Material to the Rigidbody2D (I think, or it was the collider itself) it causes a slipping like effect when on corners, and prevents sticking on walls. It allows you to get onto higher platforms than you normally would because of the slip effect, but also prevents you from getting stuck.

However, a slightly more involved way of doing it is to have the whole original collider (no feet collider) check for OnCollisionEnter2D(), then check for where the collision points are. If their Y positions are below your Y radius, you touched ground. https://docs.unity3d.com/6000.3/Documentation/ScriptReference/Collision-contacts.html

15

u/5Daydreams Feb 28 '26

Just use a 2D capsule shape, no?

1

u/moose408 Mar 01 '26

Came here to say this. This is what I have always done

7

u/shot_frost Mar 01 '26

I am making a metroidvania and here is how I do it.

  • use Rigidbody2d.Slide with gravity slip

  • use a capsule collider instead of a box collider Combined, it creates a slip effect when at the edge of the wall and you dont have the first problem.

Ground detection is done using a series of ray casts along the playe feet. It avoids the second problem, and also allows you to calculate the percentage of body on ground. This way, if I dont want to depend on gravity slip (first method) on force-falling, I can do a corner correction to make the character fall.

6

u/Carlyone Feb 28 '26

I've solved this problem in my game by having a bunch of ray-casters. Three downwards, one on the left, the right and up. That way I can easily determine which sides are being touched on my character (left, right, up, down) and determine if the character is grounded or not. Then I gate the state machine so that jump can only be performed if the character is grounded.

5

u/sharypower Mar 01 '26

Nice debug info 😁

4

u/Carlyone Mar 01 '26

Thank you! It's my way of procrastinating, making way too pretty debug tools XD

2

u/zelloxy Feb 28 '26

Why would option 2 allow jumping when next to wall? 🤔

1

u/Elesh_N Feb 28 '26

When you bump into the wall the blue box also makes contact with the wall from the side.

1

u/Gawlf85 Mar 03 '26

The "from the side" part could be greatly alleviated if you calculate the normal of the collision/hit.

If the collider/raycast didn't make contact from below but from the side, then don't allow jumping. You probably don't want to check for a perfectly vertical normal, and can introduce a bit of error margin... But if that error margin isn't too big, you shouldn't get a lot of false positives.

-2

u/zelloxy Mar 01 '26

Yeah contact but not collide/overlap? I assume there's a distinction

2

u/International_Task57 Feb 28 '26

the bottom box seems unnecessary. like. jump only works if bottom of collider is touching ground?

2

u/Elesh_N Feb 28 '26

That's the same as having a box that's one pixel tall, and the height of the box doesn't matter.

1

u/Mysterious-Sky6588 Feb 28 '26

Go with option #1 where the blue collider is slightly smaller but then change the red collider to be a capsule collider. This should make it so that if the player is standing on the verge edge of a platform they will slide off in a fairly natural way instead of just standing there unable to jump

Edit: sorry not a capsule. You want a box collider 2d but with a corner radius. The corner radius should be very small like about the difference between your collider sizes

1

u/Elesh_N Feb 28 '26

I had a capsule for a while but my players really didn't like the sliding.

1

u/Mysterious-Sky6588 Feb 28 '26

Yeah you want a box collider but with a corner radius. It's a rounded rectangle instead of a full capsule

1

u/Sypwer Feb 28 '26

Make the main collider have softer edges, so it can just fall off.

3

u/Elesh_N Feb 28 '26

Then when the player lands on a corner they will slide off, which is not what I want.

1

u/moleytron Feb 28 '26

can you also do a raycast coming from the side of the foot that if it's touching a wall it disables jumping?

3

u/Elesh_N Feb 28 '26

This would disable jumping while in a corner

3

u/Creepy_Version_6779 Mar 01 '26

I just made the floors have a separate collider layer specifically for floors

3

u/snlehton Mar 01 '26

A lot of good points here in scattered in many threads.

  1. use capsule collider if you can, easiest to work with on complex environments (slopes, pointy colliders etc). Might not work if the character is wide.

  2. use collision normal to detect if grounded (use dot product). You can also use this to detect sideways collisions.

  3. use coyote timing. Instead of just checking the ground normal, use a timestamp of last ground detection, and allow player to jump within a given time window (experiment with the threshold, 200 ms gives you very forgiving experience)

  4. to prevent getting stuck on vertical walls, check sideways collision normal and zero horizontal component if trying to move into wall. Special case is if you want to have physics pushable things, you need to be clever about it. Use this instead of setting friction to 0 as that can lead to other problems.

  5. if you have complex physics environment like one with small steps, use sideways stepping raycasts to detect when character can just step up the step without need to jump.

  6. for movement, use velocity lerping instead of using forces. This makes the character behave better.

3

u/gamedeva1day Feb 28 '26

This might sound silly and even one of the first things you tried but if you have all if the walls with the tag "wall" would writing a simple if statement for if your so many pixels away from a wall while off the ground then disable the collider?

Or would this just cause other issues?

1

u/shubhu-iron Feb 28 '26

Raycast can help since it only points downwards and so won't detect ground otherwise like if it's to the side.

1

u/CatPlanetCuties Feb 28 '26

I had the same issue so I switched to using raycast. This is the tutorial I followed https://youtu.be/OBtaLCmJexk?si=ACyOqMM5Jer8KFSG

1

u/DogSpaceWestern Feb 28 '26

Why not just a capsule or sphere shape or something? Not a programmer but have played around with hard body collision a lot so sorry if Im misunderstanding something.

1

u/Spounka Feb 28 '26

I remember having a similar issue with a prototype and I solved it by shooting multiple rays (to avoid gaps) and doing some dot product math-fu to avoid pixel bleeding jumps

The rays shoot from the sides of the collider (a bit inset, like a pixel or two) and a ray from the middle, when my player is sticking to a wall and not falling, and since I'm not grounded i shoot a ray from the bottom to the (forward) direction of the player, a very small distance, if I detect something i just push the player a tiny bit

For me that worked, it wasn't slow as you might think but it wasn't the cleanest, but again it was a prototype

1

u/Blecki Feb 28 '26

Literally never had either problem.

1

u/tidbitsofblah Mar 01 '26

How have you handled ground-check in the platforming games that you've made?

1

u/Blecki Mar 01 '26

You have to consider the normal of the surface you're touching as well.

You'd be better off with a set of ray casts as well. Boxes just give you a binary condition and you need to know the average normal, median hit object, etc.

1

u/frank_da_tank99 Feb 28 '26

Split tiles into a top half and a bottom half, if the collider intersects with the top half of a tile, the player can jump., regardless of if it's also intersecting a bottom half of a tile.

1

u/Geek4Etenity Feb 28 '26

you can get the normal direction of the object, then only make him able to jump if the normals are pointing (mostly) up

1

u/KTVX94 Mar 01 '26

We generally use capsule colliders for characters

1

u/parkway_parkway Mar 01 '26

My approach was just to have the main collider.

If that collides with a platform then the player gets stuck to the platform and can only move left and right.

They can only jump when they're stuck to a platform and also there is a small amount of coyote time if they walk off the edge when they can jump.

When stuck to a platform gravity is disabled so there isn't any vertical jittering.

1

u/SlimothyJ Mar 01 '26

I got around this problem by using 3 downward raycasts. One on each side and then one down the centre.

If any or all are detecting ground, tell your controller it's grounded.

Note that I also had ones pointing outward to prevent the physics engine clipping me into walls. But you might not need that depending on how you wrote your controller code.

1

u/Zerokx Mar 01 '26

You could make it 3 jumping colliders, adding one on the left and right that are only really small. They work for standing like the center box, but they dont give you the ability to jump

1

u/quigongingerbreadman Mar 01 '26

Also, turn the friction of the vertical surfaces to zero to keep from having the collision box "sticking" to walls. Perhaps have the friction of the side connected to a "isWall" bool on the prefab. If the goal is to have a single texture that can be placed as both floor and wall that is.

If the bool is set to true, the vertical surface friction is set to 0 (I believe you can set a small negative val to repulse slightly to prevent sticking), false it is whatever you set it to in the prefab by default. Will still possibly catch at the corners if the collision box is a simple square with perfect/sharp corners.

Another technique would be to have large chunks of the floor made as a single prefab. So instead of laying a level brick by brick, you can do it 20 bricks at a time and have an unbroken collision box for the ground/walls.

Also, many devs get around this by using a pill shaped/rounded corner collision box for player sprites. Keeps the corners from sticking on level geo.

1

u/Comfy_Jayy Mar 01 '26

U can use a raycast or ground layer detection and sometimes build some other more advanced stuff, but honestly while a ray is technically expensive, for a little 2D game these days it’s probably fine especially cause you don’t ever need to run it in update, only when you jump to see if you’re grounded (for a double jump you’d have to adapt this obviously)

1

u/PerformanceMost3734 Mar 01 '26

Also dont forget the adition of jump time, so the user is able to jump from the air next to a platform in a small window of time, this helps with the frustration an gamefeel.

1

u/fixermark Mar 01 '26

Super Mario itself might actually be a good game to reference for solutions. If I recall correctly, they used collision points, not boxes. And they decided if you could jump not with a ground collider, but by asking "Is Mario currently falling?"

... On the other hand, the game did have a bug where you could do a pixel-perfect wall jump, so YMMV.

1

u/senseven Mar 01 '26

I would also watch the commentary of the Dead Cells developer what they did to make the game a bit more fun.

1

u/Banjoman64 Mar 01 '26

In Unity 2D collisions, a small amount of extra space is left between the objects.

Knowing this, the right case should not be happening assuming both colliders are the same with and have the same x coord.

Maybe try using a few downward raycasts instead of a collider.

Someone correct me if I'm wrong please.

1

u/nukeBoyy Mar 01 '26

It's better to use capsule collider for your character that way using circular ground check with it works good in terms of behaviour

1

u/wingsneon Mar 01 '26

Use A version, no one will try jumping on the very limit edge of the hitbox unless they're trying to glitch or something - which they will find it doesn't work. And make the hitbox a bit larger.

1

u/GOD_JIMBO Mar 01 '26

https://www.youtube.com/watch?v=flaEOp5cago

Since you are using Mario as an example, I would recommend looking at how Mario actually does collisions. (Early in this video, like 2 minutes in).

It is basically a series of points in a capsule-like shape. Side collisions are the furthest out. Head is thinner than feet, so it's easier to jump up and around boxes than it is to fall off them. Hitting a side collision pushes you out, but it doesn't stop vertical velocity in either direction.

When I made a platformer and used this type of collision, i was surprised at how much better it works and feels compared to boxes!

1

u/EvonShift Mar 01 '26

Solved by just not having a separate collider. Detect ground by collision rather than overlap. Detect if collision is ground by normals.

If you use such a tall blue collider for jump buffer, It is more reliable to actually buffer the input and perform it when player hits the ground rather than jump immediately in the air.

1

u/Ancient-Pace-1507 Mar 01 '26

You can use raycasts instead of collision boxes. That should fix your problem already

1

u/Lexangelus Mar 01 '26

For my last platformer (skybolt zack) we were using 3 raycast, one left, one right and one middle. Additionnaly we were using the normal of the colliers hit by those raycasts to detect the slope angle, usefull to ignore sightly curve wall, or follow slope ground

1

u/PapaPunk17 Mar 01 '26

In my experience, using a capsule collider for the player hitbox and a box collider for the ground check avoids this problem entirely

1

u/SpaceHobo115 Mar 01 '26

Here's the thing:

A good platformer requires some grace period for you to jump, otherwise the player may come running at mach 7 and walk off the bridge and fail the jump, at which point they'll blame the game. My work around was to place two raycasts, one slightly in front of the model, and one slightly below. If they fire and either hit a ground, they player can jump, regardless of whether he's mid air or not.

1

u/anti_bot_boy Mar 01 '26

Change all collision relating to ground detection to a circle, at the bottom of the character, for enemies and others use the main box. (I dont know if this will achieve exactly what you are looking for but it will make the jumping feel good.)

1

u/Dreccon Mar 01 '26

I just made the feet collider just a tiny bit smaller than the body collider which means no matter what you do it can't touch a wall but also no matter how far over the edge you go the body collider won't touch the ground before you fall off the edge :)

1

u/ArcSemen Mar 01 '26

In Unity I recall one of the solutions was making a slippery property so you slide of from objects. worked great, It was just easier since I didnt have my setup with ray casting at all or understood the implementation fully so I keeped this cheap trick. I recommend going the extra mile because you'll be able to use the ray hit detetions for alot of mechanics I imagine .

1

u/cryonicwatcher Mar 01 '26

I would allow a jump if either the hitbox was resting on the terrain or the slightly narrower collider currently intersected it.

1

u/psioniclizard Mar 01 '26

In the case of even the old mario games a lot goes into the jumping. Someone made s good video about recreating in in godot.

I would honestly look up how they handled it in the old mario games. It's an amazing less in game design and what it takes to make something seemingly simple "feel right".

There are a ton of solutions but a lot depends on what feels correct in your game and in 2d games like this the jump is so important.

In that situation there dor example you could have 2 different colliderd as shown, one for wheb your grounded and ine for when you are airborne. But it might not be close to the best option.

1

u/thecataclysmo Mar 01 '26

Use raycast2d to detect ground not collider

1

u/[deleted] Mar 01 '26

I use Raycasting, if the ray is hitting the ground they're on the ground and can jump, if the ray is not hitting the ground they are in the air.

(using mario as an exampe cause hes there) in Mario Galaxy they used a raycast to detect the "ground" so you could run around and over and upsideown on things.

1

u/Kaljal Mar 01 '26

Just don't use blue box and put some raycast that knows what's ground and whats not also don't forget to slap some tags to the objects

1

u/MONTYvsTHEWORLD Mar 01 '26

The left scenario is more fun and forgiving anyway just build the world around it 😬

1

u/boomstik101 Mar 01 '26

Remember to add coyote time!

1

u/furezasan Mar 01 '26

i use diagonal or rounded shapes on the corners, you get both; last minute jump but if you just stand there the characters slide down. kinda depends on your physics engine's handling of slopes, but in my case it worked.

1

u/thetntm Mar 01 '26

Isn’t there a way to check if the man collider is colliding on the bottom side?

1

u/False_Bear_8645 Mar 01 '26 edited Mar 01 '26

I manage the state "on ground" with a event on Y change using a 2D raycast with some "tolerance" to make it easier for the player.

1

u/Warmedpie6 Mar 02 '26

Im assuming on the right your gravity solution is still doing its job? I usually just say y velocity should be 0.

1

u/DarkeyeMat Mar 02 '26

Build wall jumping as a mechanic lol.

1

u/Sure-Yogurtcloset-55 Mar 02 '26

Honestly my solution is two fold: first, have it only check in the down direction. Second, coyote time.

1

u/Dox_au Mar 02 '26

I calculate the bottom left pixel and bottom right pixel of my Box Collider to produce two tiny downward raycasts to determine my grounded state, and I calculate the left and right sides to produce another two horizontal raycasts to determine if I'm near a wall. This gives me pixel perfect behaviour when going over the side of a gap, and also prevents the player from wall jumping infinitely.

1

u/AcolyteArathok Mar 02 '26

Right side is actually how mario on nes played.

1

u/Malkalypse Mar 02 '26

Fun fact, this is actually how wall jumps first became a thing in games!

1

u/KitsuneMulder Mar 03 '26

You don’t actually have a problem, it’s the Nintendo ninjas intentionally breaking your code.

1

u/Primary-Grocery1158 Mar 03 '26

I just calculate the physics before drawing the sprite, so like the hitbox guys down into the ground then back up, but it only draws when the box is above the ground, this method works for walls and ceilings too

1

u/CreaMaxo Mar 03 '26

The solution is kinda simple:

Instead of having a collision block "under" the player that detects if the player can jump, why not placing a collision block above the environment where the player could jump? Then you can make that zone slightly smaller than its edge enough so that "stand on the wall" is flush yet inside the "Can jump" collider while the one sticking to the size barely, but doesn't actually touch it.

The good thing about this reverse method is that you can easily implement additional ground-related effect with those zone like slipping ice or something like a sticking floor (from which you can't jump or can't jump as high).

1

u/IpGa13 Mar 03 '26

check vertical velocity?

1

u/zylosophe Mar 03 '26

looks like the first one should fall anyway

1

u/EnDansandeMacka Mar 03 '26

maybe a state? if on ground use the right one and if midair use the left one might work (sorry if useless)

1

u/ladycatgirl Mar 03 '26

Only make top of the ground (vertically smol) as ground while using wider ground detection.

1

u/small_GameDev Mar 18 '26

I think the blue box should be wider to the main collider.

0

u/NerdicalYT Feb 28 '26

I would make the ground detection the same size as the player collider then also check to make sure your velocity is 0, would that work better?

0

u/VirtualLife76 Feb 28 '26

Aside from what others have mentioned, look up Coyote timing, it will be part of your next question.

0

u/DriftWare_ Mar 01 '26

I think coyote time is your solution here

-3

u/KaiserJustice Feb 28 '26

You can do some really stupid shit to solve this if you don’t give a shit about optimization…