Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Extra Angled Movement

Hello. I was wondering if there were a script out there that allowed different angles of movement. As it stands, there are only 8 ways of movement in the "Set Move Route" event command.

Is there any way to make a character go upper-right-right, as in 30 degrees northeast, or upper-upper-right a(60 degrees NE)? etc etc. I don't need the character to be able to do it ingame, just as a move route when an event is triggered.

Here's a diagram I hope will make it easier to see.

http://i32.tinypic.com/30joehc.jpg[/img]

Essentially, the character will be doing the movement of a Knight in chess, except going straight to that specific tile.

I was unable to find this in the script listing or the lost scripts. Is this considered the "Pixel Movement" I keep reading about? The topics I found with those specific words had broken links.

Thank you very much in advance.
 
Ok, first you need to be harassed about your math...

upper-right-right (ENE in compass) would be 22.5 degrees.
A knight's chess move would be ~26.5 degrees.

Try this out. It lets you set a factor to multiply either the X or Y movement by for angled moves.

Code:
#----------------------------------------------------------------------------
# Modified Angle Movement
#
# This script allows you to apply a factor to forced angle moves to adjust the
# amount in X or Y a character moves with a "Move Lower Right" type of move.
# (intended for use with stairs & ramps)
#
# Set XVAR & YVAR to 2 variables that you will use to signify the factors.
# The default value for either factor is 1.
# For example, if you want to move 2 tiles in X for every 1 tile in Y, set 
# the game variable[10] to '2'
#
# For custom moves, use the following event commands:
# (To move Up 1 tile, and Left 2 tiles)
#-------------------------------------------
# @>Control Variables: [0011: Y Factor] = 2
# @>Set Move Route: This Event
# :               :$>Move Upper Left
# @>Wait for Move's Completion
# @>Control Variables: [0011: Y Factor] = 1
#-------------------------------------------
# You can also reset the variable to 0, it will correct to 1.
#
# ALWAYS reset the variables to 0 or 1 after your angled move.
#  or the rest of your events & player will behave eratically.
# ALWAYS use a "Wait for Move's Completion", or the event's movement
#  will not be smooth
#
# You may also want to adjust the speed in the Move Route command,
# since you will be moving ~twice the distance in the same time.
#
# Requested By: Seita
# Created By: Brewmeister 16APR08
#
#----------------------------------------------------------------------------

class Game_Character
  XVAR = 10
  YVAR = 11
  #--------------------------------------------------------------------------
  # * Update frame (move)
  #--------------------------------------------------------------------------
  def update_move
    # Convert map coordinates from map move speed into move distance
    distance = 2 ** @move_speed
    x_factor = ($game_variables[XVAR] == 0 ? 1 : $game_variables[XVAR])
    y_factor = ($game_variables[YVAR] == 0 ? 1 : $game_variables[YVAR])
    # If logical coordinates are further down than real coordinates
    if @y * 128 > @real_y
      # Move down
      @real_y = [@real_y + distance * y_factor, @y * 128].min
    end
    # If logical coordinates are more to the left than real coordinates
    if @x * 128 < @real_x
      # Move left
      @real_x = [@real_x - distance * x_factor, @x * 128].max
    end
    # If logical coordinates are more to the right than real coordinates
    if @x * 128 > @real_x
      # Move right
      @real_x = [@real_x + distance * x_factor, @x * 128].min
    end
    # If logical coordinates are further up than real coordinates
    if @y * 128 < @real_y
      # Move up
      @real_y = [@real_y - distance * y_factor, @y * 128].max
    end
    # If move animation is ON
    if @walk_anime
      # Increase animation count by 1.5
      @anime_count += 1.5
    # If move animation is OFF, and stop animation is ON
    elsif @step_anime
      # Increase animation count by 1
      @anime_count += 1
    end
  end
  #--------------------------------------------------------------------------
  # * Move Lower Left
  #--------------------------------------------------------------------------
  def move_lower_left
    # If no direction fix
    unless @direction_fix
      # Face down is facing right or up
      @direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction)
    end
    # When a down to left or a left to down course is passable
    if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) or
       (passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
      # Update coordinates
      @x -= ($game_variables[XVAR] == 0 ? 1 : $game_variables[XVAR])
      @y += ($game_variables[YVAR] == 0 ? 1 : $game_variables[YVAR])
      # Increase steps
      increase_steps
    end
  end
  #--------------------------------------------------------------------------
  # * Move Lower Right
  #--------------------------------------------------------------------------
  def move_lower_right
    # If no direction fix
    unless @direction_fix
      # Face right if facing left, and face down if facing up
      @direction = (@direction == 4 ? 6 : @direction == 8 ? 2 : @direction)
    end
    # When a down to right or a right to down course is passable
    if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6)) or
       (passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))
      # Update coordinates
      @x += ($game_variables[XVAR] == 0 ? 1 : $game_variables[XVAR])
      @y += ($game_variables[YVAR] == 0 ? 1 : $game_variables[YVAR])
      # Increase steps
      increase_steps
    end
  end
  #--------------------------------------------------------------------------
  # * Move Upper Left
  #--------------------------------------------------------------------------
  def move_upper_left
    # If no direction fix
    unless @direction_fix
      # Face left if facing right, and face up if facing down
      @direction = (@direction == 6 ? 4 : @direction == 2 ? 8 : @direction)
    end
    # When an up to left or a left to up course is passable
    if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 4)) or
       (passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))
      # Update coordinates
      @x -= ($game_variables[XVAR] == 0 ? 1 : $game_variables[XVAR])
      @y -= ($game_variables[YVAR] == 0 ? 1 : $game_variables[YVAR])
      # Increase steps
      increase_steps
    end
  end
  #--------------------------------------------------------------------------
  # * Move Upper Right
  #--------------------------------------------------------------------------
  def move_upper_right
    # If no direction fix
    unless @direction_fix
      # Face right if facing left, and face up if facing down
      @direction = (@direction == 4 ? 6 : @direction == 2 ? 8 : @direction)
    end
    # When an up to right or a right to up course is passable
    if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 6)) or
       (passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))
      # Update coordinates
      @x += ($game_variables[XVAR] == 0 ? 1 : $game_variables[XVAR])
      @y -= ($game_variables[YVAR] == 0 ? 1 : $game_variables[YVAR])
      # Increase steps
      increase_steps
    end
  end
end

Be Well

Ref: Junk3
 
Well, I won't complain about my bad math ;3

Now I assume you meant
0010 X Factor instead of two 0011s.

It works like a dream, however when I try it out the player doesn't stop moving after one upper-left move. I've done Wait for moves completion and Erase Event right after the move route.

Here's what I put:
@>Control Variables:[0010 XVAR]=-2
@>Set Move Route: Player
: :$>Change Speed: 2
: :$>Move Upper Left
@>Control Variables:[0011 YVAR]=-1
 
Bump.

Hey brewmeister. Like I said it works perfectly, but he doesn't stop moving just after one upper-left movement, which would move him two spaces left and 1 up. It continues in that direction and freezes up the game.
 
Do you have "Repeat Action" turned on in the Move Route command?

And no, I meant to set Y factor (11) to 2, do an angled move, then set it back to 1.
I didn't set the X factor, because it stayed at 1.

The factor is multiplied by the normal distance (1) to get the desired effect. So, I'm wondering why you used negative numbers?  The general direction is controlled by which Move command you use (Upper Left,  Lower Right, etc...) The factor just changes the distance.
You said you wanted a 'chess' move,
so my example is 2 tiles left, and one tile up.  If you want to cut that in half, and have the character end up between tiles, leave Y at 1, and set X to 0.5.
You'll have to use the script command ($game_variables[10] = 0.5), because the Control Variables command rounds everything off to integers.

Be Well
 
Okay, I think I finally understand your script. I wasn't trying to have him land between tiles, for some reason I thought the negatives were to make him go upper left. Thanks so much it indeed works perfectly.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top