Hi! I'm having a weird problem with some scripts I've modified, and am looking for any insights as to what the problem could be.
Scripts I'm using:
Moghunter's 8-Way Movement, modified to show diagonal charasets.
Yanfly's Slippery Tiles script, modified for 8-way movement.
The problem:
When sliding diagonally from a non-slippery ground tile, the code works fine, as long as you don't hit any walls or corners before you stop sliding. But,
1. If you're sliding towards up-right, or down-left and you hit a wall, the player will continue sliding in that general direction until they run up against a corner. This is fine.
2. If you're sliding towards up-left or down-right, and you hit a wall, the player changes from moving up-left to up-right, or from moving down-right to down-left. This isn't suppose to happen, but I can't find where in the code the problem is occuring.
I've replicated the error in a blank project, which is attached below. Any help on this issue would be appreciated!
Edit: Updated version of Slide Test
!Slide Test.rar
[Ace] Diagonal Sliding acting weirdly at corners.
● ARCHIVED · READ-ONLY
-
-
I can't even get it to move diagonally. What buttons am I supposed to be pressing?
-
Oh sorry, hold the directional keys you want to move in (so up and left for moving up-left, for example.)
-
What changes did you make to the script? Links to the originals would be helpful.
Also, does the problem happen when you have a new project with those two scripts in their original form, without your modifications? Just to confirm whether it's an issue with the script itself or with your mods. -
Original Versions:
Moghunter's 8-Way Movement
Yanfly's Slippery TilesSpoiler#==============================================================================# +++ MOG - Simple Diagonal Movement (v1.3) +++#==============================================================================# By Moghunter# http://www.atelier-rgss.com#==============================================================================# Sistema simples de movimento na diagonal.#==============================================================================#==============================================================================# ■ Diagonal Movement#==============================================================================class Game_Player < Game_Character #-------------------------------------------------------------------------- # ● Move By Input #-------------------------------------------------------------------------- def move_by_input return if !movable? return if $game_map.interpreter.running? case Input.dir8 when 2,4,6,8; move_straight(Input.dir4) when 1 ; move_diagonal_straight(4, 2) when 3 ; move_diagonal_straight(6, 2) when 7 ; move_diagonal_straight(4, 8) when 9 ; move_diagonal_straight(6, 8) end end #-------------------------------------------------------------------------- # ● Move Diagonal Straight #-------------------------------------------------------------------------- def move_diagonal_straight(x,y) move_diagonal(x, y) return if moving? move_straight(x) ; move_straight(y) end end$mog_rgss3_simple_diagonal_movement = true
Spoiler#==============================================================================# # ▼ Yanfly Engine Ace - Slippery Tiles v1.00# -- Last Updated: 2011.12.03# -- Level: Normal# -- Requires: n/a# #==============================================================================$imported = {} if $imported.nil?$imported["YEA-SlipperyTiles"] = true#==============================================================================# ▼ Updates# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# 2011.12.03 - Started Script and Finished.# #==============================================================================# ▼ Introduction# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# Want slippery tiles without needing to make hundreds of events? Now you can!# This script binds slippery tile properties to individual tiles through usage# of notetags and terrain tags.# #==============================================================================# ▼ Instructions# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# To install this script, open up your script editor and copy/paste this script# to an open slot below ▼ Materials/素材 but above ▼ Main. Remember to save.# # -----------------------------------------------------------------------------# Tileset Notetags - These notetags go in the tileset notebox in the database.# -----------------------------------------------------------------------------# <slippery: x># <slippery: x, x># Sets the tiles marked with terrain tag x to be slippery for that particular# tileset. When the player walks over a slippery terrain, the player will keep# moving forward until stopped by an object or until the player lands on ground# without slippery properties.# #==============================================================================# ▼ Compatibility# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# This script is made strictly for RPG Maker VX Ace. It is highly unlikely that# it will run with RPG Maker VX without adjusting.# #==============================================================================module YEA module SLIPPERY_TILES #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- # - Sliding Animation - #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- # Set what sliding frame you want characters to use when they're on # slippery tiles. Standing frame is 1. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- SLIDE_FRAME = 2 end # SLIPPERY_TILESend # YEA#==============================================================================# ▼ Editting anything past this point may potentially result in causing# computer damage, incontinence, explosion of user's head, coma, death, and/or# halitosis so edit at your own risk.#==============================================================================module YEA module REGEXP module TILESET SLIPPERY = /<(?:SLIPPERY|slippery tile):[ ]*(\d+(?:\s*,\s*\d+)*)>/i end # TILESET end # REGEXPend # YEA#==============================================================================# ■ DataManager#==============================================================================module DataManager #-------------------------------------------------------------------------- # alias method: load_database #-------------------------------------------------------------------------- class <<self; alias load_database_st load_database; end def self.load_database load_database_st load_notetags_st end #-------------------------------------------------------------------------- # new method: load_notetags_st #-------------------------------------------------------------------------- def self.load_notetags_st groups = [$data_tilesets] for group in groups for obj in group next if obj.nil? obj.load_notetags_st end end end end # DataManager#==============================================================================# ■ RPG::Tileset#==============================================================================class RPG::Tileset #-------------------------------------------------------------------------- # public instance variables #-------------------------------------------------------------------------- attr_accessor :slippery #-------------------------------------------------------------------------- # common cache: load_notetags_st #-------------------------------------------------------------------------- def load_notetags_st @slippery = [] #--- self.note.split(/[\r\n]+/).each { |line| case line #--- when YEA::REGEXP::TILESET::SLIPPERY $1.scan(/\d+/).each { |num| @slippery.push(num.to_i) if num.to_i > 0 } #--- end } # self.note.split #--- end end # RPG::Tileset#==============================================================================# ■ Game_Map#==============================================================================class Game_Map #-------------------------------------------------------------------------- # new method: slippery_floor? #-------------------------------------------------------------------------- def slippery_floor?(dx, dy) return (valid?(dx, dy) && slippery_tag?(dx, dy)) end #-------------------------------------------------------------------------- # new method: slippery_tag? #-------------------------------------------------------------------------- def slippery_tag?(dx, dy) return tileset.slippery.include?(terrain_tag(dx, dy)) end end # Game_Map#==============================================================================# ■ Game_CharacterBase#==============================================================================class Game_CharacterBase #-------------------------------------------------------------------------- # new method: on_slippery_floor? #-------------------------------------------------------------------------- def on_slippery_floor?; $game_map.slippery_floor?(@x, @y); end #-------------------------------------------------------------------------- # new method: slippery_pose? #-------------------------------------------------------------------------- def slippery_pose? return false unless on_slippery_floor? return false if @step_anime return true end end # Game_CharacterBase#==============================================================================# ■ Game_Player#==============================================================================class Game_Player < Game_Character #-------------------------------------------------------------------------- # alias method: dash? #-------------------------------------------------------------------------- alias game_player_dash_st dash? def dash? return true if on_slippery_floor? return game_player_dash_st end #-------------------------------------------------------------------------- # alias method: update #-------------------------------------------------------------------------- alias game_player_update_st update def update game_player_update_st update_slippery end #-------------------------------------------------------------------------- # new method: update_slippery #-------------------------------------------------------------------------- def update_slippery return if $game_map.interpreter.running? return unless on_slippery_floor? return if moving? move_straight(@direction) end #-------------------------------------------------------------------------- # new method: pattern #-------------------------------------------------------------------------- def pattern return YEA::SLIPPERY_TILES::SLIDE_FRAME if slippery_pose? return @pattern end end # Game_Player#==============================================================================# ■ Game_Follower#==============================================================================class Game_Follower < Game_Character #-------------------------------------------------------------------------- # new method: pattern #-------------------------------------------------------------------------- def pattern return YEA::SLIPPERY_TILES::SLIDE_FRAME if slippery_pose? return @pattern end end # Game_Follower#==============================================================================# # ▼ End of File# #==============================================================================
My changes:
Moghunter:
Yanfly:Spoilerclass Game_Player < Game_Character#--------------------------------------------------------------------------# ● Move By Input#--------------------------------------------------------------------------def move_by_input return if !movable? return if $game_map.interpreter.running? case Input.dir8 when 2,4,6,8 move_straight(Input.dir4) @character_index = 0 #Added this to change player graphic to show orthogonal (Up, left, down, right poses) @diagonal = false #Added this so that Slippery Script can detect if moving diagonally. when 1 move_diagonal_straight(4, 2) @direction = 2 #Added this to each case. Sets character facing so that proper graphic is displayed. when 3 move_diagonal_straight(6, 2) @direction = 6 when 7 move_diagonal_straight(4, 8) @direction = 4 when 9 move_diagonal_straight(6, 8) @direction = 8 end end#--------------------------------------------------------------------------# ● Move Diagonal Straight#--------------------------------------------------------------------------def move_diagonal_straight(x,y)move_diagonal(x, y) @diagonal = true #Added this so that Slippery Script can detect if moving diagonally. @character_index = 1 #Added this to change player graphic to show diagonals. return if moving? move_straight(x) move_straight(y)endend
Spoiler#-------------------------------------------------------------------------- # new method: update_slippery #-------------------------------------------------------------------------- def update_slippery return if $game_map.interpreter.running? return unless on_slippery_floor? return if moving?#My changes begin here. if @diagonal #If moving diagonally case @direction #Determine what diagonal direction to move character in. when 2 ; move_diagonal_straight(4, 2) when 6 ; move_diagonal_straight(6, 2) when 4 ; move_diagonal_straight(4, 8) when 8 ; move_diagonal_straight(6, 8) end else move_straight(@direction) end#Changes end. end
The problem can't be replicated using the original scripts, because Yanfly's Slippery Tiles script only takes orthogonal directions (up, left, down, right) into consideration, and not diagonals.
As far as I can tell, my mods need to account for something that happens when the player bumps up against a wall, but I can't seem to find where something like that could be. -
I think this is a bit of an improvement, but it's still not displaying the correct graphic (though it does seem to be moving in the correct direction)
Code:def move_diagonal_straight(x,y) move_diagonal(x, y) @diagonal = true @character_index = 1 return if moving? @diagonal = false move_straight(x) move_straight(y) if !moving? end -
Thanks Shaz. I tried implementing the change, and it works better. I tried experimenting a bit more as well and found new behaviour oddities, summarized below:
Move up-left Hit horizontal wall first Start at least one tile away: Slides properly. Start right beside wall: Slides properly. Hit vertical wall first Start at least one tile away: Slides properly, but graphic changes to up-right upon hitting wall. Start right beside wall: Not working. Stops moving as soon as release arrow keys.Move up-right Hit horizontal wall first Start at least one tile away: Slides properly, but graphic changes to down-right upon hitting wall. Start right beside wall: Not working. Stops moving as soon as release arrow keys. Hit vertical wall first Start at least one tile away: Slides properly. Start right beside wall: Slides properly.Move down-left Hit horizontal wall first Start at least one tile away: Slides properly, but graphic changes to up-left upon hitting wall. Start right beside wall: Not working. Stops moving as soon as release arrow keys. Hit vertical wall first Start at least one tile away: Slides properly. Start right beside wall: Slides properly.Move down-right Hit horizontal wall first Start at least one tile away: Slides properly. Start right beside wall: Slides properly. Hit vertical wall first Start at least one tile away: Slides properly, but graphic changes to down-left upon hitting wall. Start right beside wall: Not working. Stops moving as soon as release arrow keys.
I've attached the updated version.
!Slide Test.rar