Lemony's Camera - Camera non-centered issue

ZirconStorms

Veteran
Veteran
Joined
Dec 22, 2014
Messages
359
Reaction score
110
First Language
English
Primarily Uses
RMVXA
Script is taken from a Steam Workshop 2013 re-release. Can't find working links to the script on it's own.

Code:
#==============================================================================
# ** Lemony's Smooth Map Scrolling (LSMS), (ReStaff March 2013), v.1.0
#==============================================================================
#  This scripts makes the camera move smoothly, but not just while following
# the player but also when using scroll map event commands and in loop maps,
# since it changes how the map scroll is handled by the system.
#==============================================================================
# (*) How to use.-
#==============================================================================
# * You can change the strength of the movement delay by editing LSMS_STR to
# any number you wish, lower values means less delay, and bigger values means
# a stronger delay.
#
# * You can turn off the system at any time during the game, by activating the
# switch that has the id that you can specify in LSMS_SWT variable below.
#
# * The script adjusts the delay strength on the run to avoid letting the
# player off screen when the player is moving or running, to do this, it uses
# a base  value that represents the base speed of the player, change that value
# in LSMS_SPD if you use another default speed for the player. (Default is 4)
#==============================================================================
# (**) Terms of Use.-
#==============================================================================
# This script is free to use in any non commercial game or project created with
# any RPG Maker with a valid license as long as explicit credits are given to
# the author (Lemony).
# If you want to use this script in a commercial game, you must pay a one time
# fee of USD 6.99 per title plus explicit credits to the author (Lemony).
#==============================================================================
class Game_Map
  #--------------------------------------------------------------------------
  # * Smooth Scrolling Delay Strength.                                  [OPT]
  #--------------------------------------------------------------------------
  LSMS_STR = 69
  #--------------------------------------------------------------------------
  # * Smooth Scrolling Off Switch (System goes off when activated).     [OPT]
  #--------------------------------------------------------------------------
  LSMS_SWT = 10
  #--------------------------------------------------------------------------
  # * Default Game Player Speed.                                        [OPT]
  #--------------------------------------------------------------------------
  LSMS_SPD = 4
  #--------------------------------------------------------------------------
  # * Alias Setup.                                                      [MOD]
  #--------------------------------------------------------------------------
  alias lsms_setup setup
  def setup(map_id)
    lsms_setup(map_id)
    @lsms_real_x = @lsms_real_y = 0
  end
  #--------------------------------------------------------------------------
  # * Alias Scroll Down.                                                [MOD]
  #--------------------------------------------------------------------------
  alias lsms_scroll_down scroll_down
  def scroll_down(distance)
    if $game_switches[LSMS_SWT]
      lsms_scroll_down(distance)
      return
    end
    if loop_vertical?
      @lsms_real_y += distance
      if @display_y > @map.height
        @lsms_real_y %= @map.height
        @display_y %= @map.height
      end
      @parallax_y += distance if @parallax_loop_y
    else
      last_y = @lsms_real_y
      @lsms_real_y = [@lsms_real_y + distance, (self.height - screen_tile_y)].min
      @parallax_y += @lsms_real_y - last_y
    end
  end
  #--------------------------------------------------------------------------
  # * Alias Scroll Left.                                                [MOD]
  #--------------------------------------------------------------------------
  alias lsms_scroll_left scroll_left
  def scroll_left(distance)
    if $game_switches[LSMS_SWT]
      lsms_scroll_left(distance)
      return
    end
    if loop_horizontal?
      @lsms_real_x -= distance
      if @display_x < 0
        @lsms_real_x %= @map.width
        @display_x %= @map.width
      end
      @parallax_x += distance if @parallax_loop_x
    else
      last_x = @lsms_real_x
      @lsms_real_x = [@lsms_real_x - distance, 0].max
      @parallax_x += @lsms_real_x - last_x
    end
  end
  #--------------------------------------------------------------------------
  # * Alias Scroll Right.                                               [MOD]
  #--------------------------------------------------------------------------
  alias lsms_scroll_right scroll_right
  def scroll_right(distance)
    if $game_switches[LSMS_SWT]
      lsms_scroll_right(distance)
      return
    end
    if loop_horizontal?
      @lsms_real_x += distance
      if @display_x > @map.width
        @lsms_real_x %= @map.width
        @display_x %= @map.width
      end
      @parallax_x += distance if @parallax_loop_x
    else
      last_x = @lsms_real_x
      @lsms_real_x = [@lsms_real_x + distance, (self.width - screen_tile_x)].min
      @parallax_x += @lsms_real_x - last_x
    end
  end
  #--------------------------------------------------------------------------
  # * Alias Scroll UP.                                                  [MOD]
  #--------------------------------------------------------------------------
  alias lsms_scroll_up scroll_up
  def scroll_up(distance)
    if $game_switches[LSMS_SWT]
      lsms_scroll_up(distance)
      return
    end
    if loop_horizontal?
      @lsms_real_y -= distance
      if @display_y < 0
        @lsms_real_y %= @map.height
        @display_y %= @map.height
      end
      @parallax_y += distance if @parallax_loop_y
    else
      last_y = @lsms_real_y
      @lsms_real_y = [@lsms_real_y - distance, 0].max
      @parallax_y += @lsms_real_y - last_y
    end
  end
  #--------------------------------------------------------------------------
  # * Update Scroll.                                                    [MOD]
  #--------------------------------------------------------------------------
  alias lsms_update_scroll update_scroll
  def update_scroll
    if !$game_switches[LSMS_SWT]
      x = ((@display_x - @lsms_real_x) ** 2 + (@display_x - @lsms_real_x) ** 2)
      y = ((@display_y - @lsms_real_y) ** 2 + (@display_y - @lsms_real_y) ** 2)
      spd_cor = (($game_player.real_move_speed - LSMS_SPD) * LSMS_STR)
      px = Math.sqrt(x) / [2, ((2 + (2 * LSMS_STR)) - spd_cor)].max
      py = Math.sqrt(y) / [2, ((2 + (2 * LSMS_STR)) - spd_cor)].max
      @display_x += (@display_x < @lsms_real_x) ? px : -px
      @display_y += (@display_y < @lsms_real_y) ? py : -py
      return unless scrolling?
      last_x = @display_x
      last_y = @display_y
      do_scroll(@scroll_direction, scroll_distance)
      @scroll_rest -= scroll_distance
    else
      lsms_update_scroll
    end
  end
  #--------------------------------------------------------------------------
  # * Calculate Scroll Distance.                                        [MOD]
  #--------------------------------------------------------------------------
  alias lsms_scroll_distance scroll_distance
  def scroll_distance
    lsms_on = !$game_switches[LSMS_SWT]
    lsms_on ? (2 ** @scroll_speed / 128.0) : lsms_scroll_distance
  end
end
Specifically, this section:
Code:
  alias lsms_setup setup
  def setup(map_id)
    lsms_setup(map_id)
    @lsms_real_x = @lsms_real_y = 0
  end
When smooth scrolling is enabled, map transfers + player starting positions leads to the camera not being centered on the player character. picture:
upload_2019-3-30_10-11-20.png

It's an edit over Game_Map, but I don't know how the engine/default code naturally centers the camera on the player sprite (when it can, anyway - exceptions being when you get to corners of maps and all that). This error(?) occurs with just this script in-game and nothing else added or modified to a blank RPG Maker project, so you can recreate this issue without needing the demo (place the player in a large map and paste the script under Materials).

Demo has been attached below.

EDIT:

I think it may actually be these sections also causing issues:
Code:
alias lsms_update_scroll update_scroll
  def update_scroll
    if !$game_switches[LSMS_SWT]
      x = ((@display_x - @lsms_real_x) ** 2 + (@display_x - @lsms_real_x) ** 2)
      y = ((@display_y - @lsms_real_y) ** 2 + (@display_y - @lsms_real_y) ** 2)
      spd_cor = (($game_player.real_move_speed - LSMS_SPD) * LSMS_STR)
      px = Math.sqrt(x) / [2, ((2 + (2 * LSMS_STR)) - spd_cor)].max
      py = Math.sqrt(y) / [2, ((2 + (2 * LSMS_STR)) - spd_cor)].max
      @display_x += (@display_x < @lsms_real_x) ? px : -px
      @display_y += (@display_y < @lsms_real_y) ? py : -py
      return unless scrolling?
      last_x = @display_x
      last_y = @display_y
      do_scroll(@scroll_direction, scroll_distance)
      @scroll_rest -= scroll_distance
    else
      lsms_update_scroll
    end
  end
  #--------------------------------------------------------------------------
  # * Calculate Scroll Distance.                                        [MOD]
  #--------------------------------------------------------------------------
  alias lsms_scroll_distance scroll_distance
  def scroll_distance
    lsms_on = !$game_switches[LSMS_SWT]
    lsms_on ? (2 ** @scroll_speed / 128.0) : lsms_scroll_distance
  end
end
 

Attachments

Last edited:

ZirconStorms

Veteran
Veteran
Joined
Dec 22, 2014
Messages
359
Reaction score
110
First Language
English
Primarily Uses
RMVXA
Bump.
Not expecting many results, but it's worth a shot.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Finally finished my first big game since joining the forums! Please check out Petal Knights! https://forums.rpgmakerweb.com/index.php?threads/petal-knights-playable-now.117898/
Back home now :cutesmile:

Many thanks to all my fellow game devs. for all the support during this crazy time.

Feeling a bit rough but much better then bein' hospitalized at least.

Now time to get back to the code :D
Added skill ranges, and very basic implementation of scope, with a rule called "empty tile" that simply returns true if the selected tile is empty (has a battler), and false otherwise


This means movement range and attack ranges are all automatically implemented.

More info: https://himeworks.itch.io/grid-battle-system/devlog/167442/devlog-3-basic-skill-range
Stone masons are hard at work creating beautiful sculptures for your games...
When you realize @Kupotepo is a champion among RM Web users, and it all makes sense now:

Forum statistics

Threads
100,465
Messages
976,273
Members
132,082
Latest member
nwr
Top