Hello! I'm trying to make Yume Nikki style movement where everything works on a grid system. When you let go of up for example, it will keep moving you up until you move to a proper position on the grid.
https://youtu.be/Yr4iJL1LZwY?si=o_M7D7ozYrZG9ja_&t=6277
I have figured out how to get it working for up, but it won't work if I just copy it to the other directions because they would start to conflict with each other. How could I make this logic work properly? Is there a simpler way to do this?
extends CharacterBody2D
@export var speed_stat: int = 16
var speed_real: int = speed_stat * 16
var tile_size: float = 16
var moving: bool = false
func _physics_process(delta: float) -> void:
velocity = Vector2()
if Input.is_action_pressed("up"):
if moving == false:
velocity.y -= speed_stat
velocity.x = 0
if position.y as int % 16 != 7:
velocity.y -= speed_stat
moving = true
else:
moving = false
if Input.is_action_pressed("down"):
position.y += speed_stat
velocity.x = 0
#if position.y as int % 16 != 8:
# velocity.y += speed_stat
if Input.is_action_pressed("left"):
position.x -= speed_stat
velocity.y = 0
if position.x as int % 16 != 7:
velocity.x -= speed_stat
if Input.is_action_pressed("right"):
position.x += speed_stat
velocity.y = 0
#if position.x as int % 16 != 8:
# velocity.x += speed_stat
move_and_slide()
Game: https://store.steampowered.com/app/650700/Yume_Nikki/
This is a longplay of the Steam version of Yume Nikki, the 2004 cult classic RPG Maker surreal horror adventure from the reclusive Kikiyama. I originally uploaded a version of video on 26 Jan 2019, but I have since realized I accidentally removed the segment in which Madotsuki attains ...