Currently I am using the following script for a tile size of 16 and a walk speed of 4.

		percent_moved_to_next_tile += walk_speed * delta
		
		if percent_moved_to_next_tile >= 1.0:
			percent_moved_to_next_tile = 0.0
			is_moving = false
		else:
			position = initial_posistion + (Tile_Size * input_direction * percent_moved_to_next_tile)

If I change the walk speed to anything other than 4, its possible to end up between tiles due to "percent_moved_to_next_tile". I was wondering if anyone had any ideas for a smooth transform from initial position to end position. I think Interpolation would work Im just not sure how to go about it. In unity this would be as simple as:

		isMoving = true
		
		while ((targetPos - transform.position).sqrMagnitude > Mathf.Epsilon)
		{
			transform.position = Vector3.MoveTowards(transform.position, targetPos, movementSpeed * Time.delta)
		}
		transform.position = targetPos;
		isMoving = false;

Walk speed 4: move 1 tile.


Walk speed 8: move 1 tile


  • retroshark replied to this.
  • retroshark You're answer helped me troubleshoot a way to figure it out but I didn't do exactly what you said XD I ended up adding a target position variable and forcing the position in the if >=0 statement. A little bit stuttery with extreme speeds but works great for the 2 speeds ill be using.

    		var target_pos : Vector2 = initial_posistion + (input_direction*Tile_Size)
    
    		percent_moved_to_next_tile += walk_speed * delta
    		
    		if percent_moved_to_next_tile >= 1.0:
    			position = target_pos
    			percent_moved_to_next_tile = 0.0
    			is_moving = false
    		else:
    			position = initial_posistion + (Tile_Size * input_direction * percent_moved_to_next_tile)

    KlownHero you could add a check after percent_moved_to_next_tile has completed and snap the character the the grid. Essentially not letting it move into the next tile and be sure that it’s moved enough in the current tile.

      retroshark You're answer helped me troubleshoot a way to figure it out but I didn't do exactly what you said XD I ended up adding a target position variable and forcing the position in the if >=0 statement. A little bit stuttery with extreme speeds but works great for the 2 speeds ill be using.

      		var target_pos : Vector2 = initial_posistion + (input_direction*Tile_Size)
      
      		percent_moved_to_next_tile += walk_speed * delta
      		
      		if percent_moved_to_next_tile >= 1.0:
      			position = target_pos
      			percent_moved_to_next_tile = 0.0
      			is_moving = false
      		else:
      			position = initial_posistion + (Tile_Size * input_direction * percent_moved_to_next_tile)