godot-escoria / escoria-issues

Central Escoria issue tracker
3 stars 0 forks source link

Request: Pixel-perfect movement with Escoria #260

Open hobbesjaap opened 2 years ago

hobbesjaap commented 2 years ago

Please make sure you talk to the community before creating an issue. Asked in Discord and was invited to open this as an issue here.

Is your feature request related to a problem? Please describe. No

Describe the solution you'd like I would like Escoria to implement a pixel-perfect movement system for characters. A similar request within Godot was discussed here.

My background is with Adventure Game Studio, where this feature is hard-coded in. My game is set to a resolution of 320x200 and I would like the movement vector to be rounded to Integers, rather than in floats. This would result in more "accurate" old-school adventure game behaviour similar to the 90s adventure games.

Describe alternatives you've considered The only alternative I think is to not implement this, which isn't the end-of-the-world, but the smoothness of movement, which isn't pixel perfect, does stand out visually to me.

Additional context It might be helpful to people with vastly superior coding skills than I have to look at certain YouTube videos. I imagine this level of movement is more important for platform games, but the visual immersion also applies to PnC games.

hobbesjaap commented 2 years ago

Further to this, I realise this is a desirable feature when working in low-res pixelart games, but less desirable when working in higher res (since it removes some of the smoothness, perhaps).

No idea how feasible / easy this is, but perhaps the game.esc file can have an "options" area to define these more "in depth" features?

So an :options section that then haspixel_perfect_movement = 1;

Or something like that?

Coming from Adventure Game Studio, which has obviously had two decades to mature with features to approach old-school pixel art adventure games, I'm most excited about blending modern techniques (procedural lighting, shaders) with as-accurate-as-possible pixel-based approaches.

BHSDuncan commented 2 years ago

Sounds good to me. @StraToN @dploeger what do you guys think? 4.1 or Future?

StraToN commented 2 years ago

4.1 may be possible.

balloonpopper commented 2 years ago

@hobbesjaap - this might not be the right way to do this (I can't tell for sure as I don't have a low-res pixel project to check against), but see if this works on your end as a quick fix. In file addons/escoria-core/game/core-scripts/behaviors/esc_movable.gd, find the function

func _calculate_movement(delta: float):

It's line 95 on the current codebranch. After this line

new_pos = pos + dir * movement_speed * parent.v_speed_damp

add the last line as shown below ("new_pos = new_pos.floor()") to round the pixel location. (I'll put the few lines before it as well so it's in context)

    var new_pos: Vector2
    if pos.distance_to(next) < movement_speed:
        new_pos = next
        path_ofs += 1
    else:
        new_pos = pos + dir * movement_speed * parent.v_speed_damp
        new_pos = new_pos.floor()