Godot Version
4.5
Question
So I’m trying to make tiles that the player slides across, but for some reason it’s not working as intended, aka the velocity is only in the range of -1 to 1, and thus the player moves only a little bit. I know the ice detection is working correctly, so it’s probably the physics part of the code that isn’t correct.
Here’s the relevant code:
velocity = Vector2.ZERO
var input = Vector2.ZERO
var direction = Vector2.ZERO
if Input.is_action_pressed("up"):
input.y -= 1
direction = Vector2(0, -1)
if Input.is_action_pressed("down"):
input.y += 1
direction = Vector2(0, 1)
if Input.is_action_pressed("left"):
input.x -= 1
direction = Vector2(-1, 0)
if Input.is_action_pressed("right"):
input.x += 1
direction = Vector2(1, 0)
if tilemap != null:
var tile_data = tilemap.get_cell_tile_data(tilemap.local_to_map(Vector2(global_position.x, global_position.y)))
if tile_data:
if tile_data.get_custom_data("is_ice"):
if direction:
velocity = lerp(velocity, direction * ice_slide_speed, 0.01)
else:
velocity = lerp(velocity, Vector2.ZERO, 0.01)
move_and_slide()
This is in _physics_process, of course. What am I doing wrong here?