Jump to content
UncannyBoots

Galv Camera Slide issue

Recommended Posts

I'm back again lol. As usual I already have a gist of what needs to be done but I don't know how to actually write code in RGSS3.

Unlike my last problem though I do believe this one will be a lot easier.

So I'm using Galv's Cam Slide script. When riding a motorcycle in my game, you have the option to speed up. It goes very fast and when going up or down, the player outruns the screen cam slide, going off screen.

The solution I'm thinking of is to change "ch = (Graphics.height / 2)" to be something like "ch = (Graphics.height / 2 + 100)" when the player is holding the up key and the shift key, and "ch = (Graphics.height / 2 - 100)" when the player is holding the down key and the shift key.

How would you write that?

Example:

if [up key is pressed] && [shift key is pressed]

    ch = (Graphics.height / 2 + 100)

elsif [down key is pressed] && [shift key is pressed]

    ch = (Graphics.height / 2 - 100)

else

    ch = (Graphics.height / 2)

end

 

Replace the stuff inside "[ ]" with the actual script code.

I don't know if you have to define button directions or not though

 

Here's the script:

#------------------------------------------------------------------------------#
#  Galv's Cam Slide Control
#------------------------------------------------------------------------------#
#  For: RPGMAKER VX ACE
#  Version 1.0
#------------------------------------------------------------------------------#
#  2015-10-09 - Version 1.0 - release
#------------------------------------------------------------------------------#
# This script gives the camera a slide effect and also more control of where
# the camera is focused. You can set it to follow an event or scroll to an x,y
# position on the map.
 
 
 
#-------------------------------------------------------------------------------
#  SCRIPT CALL
#-------------------------------------------------------------------------------
# $game_map.camslide(status)      # status can be true or false (default true)
#
#                                 # when false - cam reverts to default,
#                                 # does not slide and 'scroll map' event works
#
#                                 # when true - slide effect and targeting
#                                 # works but 'scroll map' does not.
#
# $game_map.camtarget(x,s)        # x is event ID
#                                 # s is speed of camera scroll (800 default)
#                                 # the greater the speed the slower the scroll
#                                 # sets camslide to true automatically.
#
# $game_map.camtarget_xy(x,y,s)   # x,y are the x,y co-ordinates on the map.
#                                 # s is speed (same as above)
#                                 # sets camslide to true automatically.
#
# $game_map.cam_default           # sets camtarget back to player
#                                 # sets camslide to true automatically.
#-------------------------------------------------------------------------------
 
class Game_Player < Game_Character
 
  alias galv_scroll_gp_gc_update_scroll update_scroll
  def update_scroll(last_real_x, last_real_y)
    return if !$game_map.free_cam
    galv_scroll_gp_gc_update_scroll(last_real_x, last_real_y)
  end
 
end
 
 
 
class Game_Map
  attr_accessor :free_cam
  attr_accessor :camtarget
   
  alias galv_scroll_gm_initialize initialize
  def initialize
    galv_scroll_gm_initialize
    cam_default
  end
   
  def camslide(status)
    @free_cam = !status
  end
 
  alias galv_scroll_gm_setup setup
  def setup(map_id)
    cam_default
    galv_scroll_gm_setup(map_id)
  end
   
  def camtarget(x, spd = 800)
    @camtarget = @events[x]
    @free_cam = false
    @camspeed = spd
  end
   
  def camtarget_xy(x,y,spd = 800)
    @camtarget = Camxytarget.new
    @camtarget.camxy(x,y)
    @free_cam = false
    @camspeed = spd
  end
   
  def cam_default(speed = 800)
    @camtarget = $game_player
    @free_cam = false
    @camspeed = speed
  end
   
  alias galv_scroll_gm_update_scroll update_scroll
  def update_scroll
     
    return galv_scroll_gm_update_scroll if @free_cam
    @scroll_rest = 0
    cw = (Graphics.width / 2)
    ch = (Graphics.height / 2)
     
    sx = 0.016 + (@camtarget.screen_x - cw).abs / @camspeed
    sy = 0.016 + (@camtarget.screen_y - ch).abs / @camspeed
    y_pos = @camtarget.screen_y.to_i
    x_pos = @camtarget.screen_x.to_i
    if y_pos < ch
      $game_map.scroll_up(sy)
    elsif y_pos > ch
      $game_map.scroll_down(sy)
    end
    if x_pos < cw
      $game_map.scroll_left(sx)
    elsif x_pos > cw
      $game_map.scroll_right(sx)
    end
  end
   
end
 
 
class Camxytarget < Game_CharacterBase
 
  def camxy(x,y)
    @x = x
    @y = y
    @real_x = @x
    @real_y = @y
  end
end

 

Edited by UncannyBoots

Share this post


Link to post
Share on other sites

Input.press?(:DOWN)
Input.press?(:UP)
Input.press?(:SHIFT)
Input.press?(:ALT)
Input.press?(:CTRL)
Input.press?(:F5)
Input.press?(:F6)
Input.press?(:F7)
Input.press?(:F8)
Input.press?(:LEFT)
Input.press?(:RIGHT)
Input.press?(:A)
Input.press?(:B)
Input.press?(:C)
Input.press?(:X)
Input.press?(:Y)
Input.press?(:Z)
Input.press?(:L)
Input.press?(:R)

I'd also use (:A) instead of (:SHIFT).

Edited by PhoenixSoul

Share this post


Link to post
Share on other sites
21 hours ago, PhoenixSoul said:

Input.press?(:DOWN)
Input.press?(:UP)
Input.press?(:SHIFT)
Input.press?(:ALT)
Input.press?(:CTRL)
Input.press?(:F5)
Input.press?(:F6)
Input.press?(:F7)
Input.press?(:F8)
Input.press?(:LEFT)
Input.press?(:RIGHT)
Input.press?(:A)
Input.press?(:B)
Input.press?(:C)
Input.press?(:X)
Input.press?(:Y)
Input.press?(:Z)
Input.press?(:L)
Input.press?(:R)

I'd also use (:A) instead of (:SHIFT).

Thank you! I knew about those commands in the back of my mind but for some reason I couldn't remember them until reading your post. I've got bad memory I guess 😅

Share this post


Link to post
Share on other sites

I'm actually having another issue.

I wrote "if Input.press?(:A) && Input.press?(:UP) && $game_player.moving?" and the screen stutters and lags a bunch. Removing game_player.moving will remove the lag, but the moving check is critical because if the player isn't moving, then the camera should not move when an input is pressed.

How would I make it so that the script doesn't constantly refresh and check if the player is moving every frame? I think that's what the problem is

Share this post


Link to post
Share on other sites

The only thing I could think of is to bind the $game_player.moving? to a switch, and have
[if Input.press?(:A)&&Input.press?(:UP)]  include [&&$game_switches[#]] instead. I don't know if this will fix the lag or not.

Share this post


Link to post
Share on other sites
17 hours ago, PhoenixSoul said:

The only thing I could think of is to bind the $game_player.moving? to a switch, and have
[if Input.press?(:A)&&Input.press?(:UP)]  include [&&$game_switches[#]] instead. I don't know if this will fix the lag or not.

I'll give it a try, I'll report back here when I finish

 

Edit: It didn't work :/

 

This is the code I currently have, starting with the line with "cw=" in the script

    cw = (Graphics.width / 2)
    if !$game_switches[169]
      ch = (Graphics.height / 2)
    else
      if Input.press?(:A) && Input.press?(:UP) && $game_player.moving? && !Input.press?(:RIGHT) && !Input.press?(:LEFT)
        ch = (Graphics.height / 2 + 120)
      elsif Input.press?(:A) && Input.press?(:DOWN) && $game_player.moving? && !Input.press?(:RIGHT) && !Input.press?(:LEFT)
        ch = (Graphics.height / 2 - 100)
      else
        ch = (Graphics.height / 2)
      end
    end

If you want to test it out, make a common event with a cond branch where if switch 169 is on, character speed is 5. That will match the effect I have when player is on the bike and when you press shift, the player will speed up to 6. The resolution of my game is also weird, it's 512x288, a 16:9 aspect ratio, so that's why when moving up or down at a speed of 6, the player goes off of the screen. I have customized all of my menus to fit this resolution and I like how it makes my game have a more pixel art look so I don't want to change the resolution as a solution to this problem

 

Another edit:

I just noticed that when going left then turning up and keeping your finger on the left key (or right), the camera change doesn't activate. I put !input.press(left)/(right) there in order to prevent the opposite from happening -- from keeping the up key active while moving left/right.

So there's just all sorts of things going wrong here. Is there perhaps a command like $game_player.moving? that checks if the player is moving up? That would omit the directional key checks entirely while maintaining the same effect. (Fun fact: that's actually what I originally asked in this topic before editing the original post because I thought it'd be more convenient to just use a key check. I'm stupid like that)

Perhaps $game_player.moving? && [check if player facing up]?

^Crossed out the above because I think it'll be an easy issue to fix. I want to focus more on the screen stuttering/lag issue in this thread.

Tbh "lag" isn't the right word. It is more like screen stuttering. When you remove 'game_player.moving?" the effect is very smooth. Add that line in and it isn't smooth. I don't know why that is and it's jarring because the camera will be smooth when going left/right but not up/down.

Edited by UncannyBoots

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×