Jump to content
New account registrations are disabed. This website is now an archive. Read more here.
  • 0
Jiyujin

Restrict character movement

Question

I want to make a part of a game where the character can only move to the left or the right and not be able to move or turn up or down. Is this possible?

I was thinking of just making the sprite not have the front and back view, and replace them with left and right. But, then if I try to turn up or down the character will change change to what ever direction I made it. You know?

Is there any way to do this?

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

If I understood what you were wanting, the script I created below should do what you want.

 

Copy this script and insert it above Main in the script dialogue box (press F11 in the main editor).  All you have to do to restrict your character's movement is enter restrict in the script command of an event's third page.  To turn off the restriction, enter unrestrict in the script command.  Do you know how you want to free the player's restriction.  Keep in mind that you won't be able to turn up or down, so if the player needs to select an object of some sort, it will need to be on the same level as him.  I hope this is what you were looking for, and I tried to make it as easy to use as possible.  Let me know if you have any questions.

 

 

 

#global method for ease of initiation
def restrict
$game_temp.movement_restricted = true
end
#global method for ease of termination
def unrestrict
$game_temp.movement_restricted = false
end

# Modifies Game_Temp to hold the restrict_movement variable
class Game_Temp

attr_accessor :movement_restricted

alias old_initialize initialize

def initialize

old_initialize

@movement_restricted = false

end

end

class Game_Character
#--------------------------------------------------------------------------
# * Move Down
# turn_enabled : a flag permits direction change on that spot
#--------------------------------------------------------------------------
def move_down(turn_enabled = true)
# Checks for special movement restriction
if $game_temp.movement_restricted == false
# Turn down
if turn_enabled
turn_down
end
# If passable
if passable?(@x, @y, 2)
# Turn down
turn_down
# Update coordinates
@y += 1
# Increase steps
increase_steps
# If impassable
else
# Determine if touch event is triggered
check_event_trigger_touch(@x, @y+1)
end
end
end

#--------------------------------------------------------------------------
# * Move up
# turn_enabled : a flag permits direction change on that spot
#--------------------------------------------------------------------------
def move_up(turn_enabled = true)
# Checks for special movement restriction
if $game_temp.movement_restricted == false
# Turn up
if turn_enabled
turn_up
end
# If passable
if passable?(@x, @y, 8)
# Turn up
turn_up
# Update coordinates
@y -= 1
# Increase steps
increase_steps
# If impassable
else
# Determine if touch event is triggered
check_event_trigger_touch(@x, @y-1)
end
end
end

end

 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...