I'm trying to get the player to move toward a building entrance (event 14) when met by a guard (Event A). For the moment i have a loop in event A starting on contact with event A with exit condition of being at the entrance that does this script call ˋˋˋ$game_player.move_toward_character($game_map.events[14])ˋˋˋ. I always end up with the game freezing when the loop is reached. Anyone knows why is that?
Player forcingly walking toward event
● ARCHIVED · READ-ONLY
-
-
don't use a script call, use set move route targeted on the player instead.
that way you can set the options correctly and don't need a loop
if that doesn't work directly, we need to see how you made the event, give us a screenshot of it. -
The thing is that I want the contact with the player to be possible anywhere on the map and still resolve correctly. The set route didn't give me the oppurtunity of doing steps depending on were the player is now. Also, here are screenshots (sorry I didn't send them first i had too change languages.
-
Use variables for coordinates and loops - check the player position against the coordinate you want them to ultimately be, and loop step actions into that direction. Say on the x coordinate they are lower than intended, player moves right, and if they are higher than intended, move left. Once the x coordinate matches, break the loop. After that, check with the y coordinate - if they higher than the coordinate, move up, and if lower than the coordinate, move down. That way it should be possible to guide the player towards a particular position, from which you then can enforce a strict moveroute as usual.
Code:$game_variables[yourXhere]=$game_player.x $game_variables[yourYhere]=$game_player.y
Use these codes, insert the player position in the loops via regular script call and do the regular "Value is bigger/smaller/same" stuff. -
yeah but doing that am I not just rewriting the move_toward_character method from Game_Character? (Could I not use it to do what I want?)
Code:def move_toward_character(character) sx = distance_x_from(character.x) sy = distance_y_from(character.y) if sx.abs > sy.abs move_straight(sx > 0 ? 4 : 6) move_straight(sy > 0 ? 8 : 2) if !@move_succeed && sy != 0 elsif sy != 0 move_straight(sy > 0 ? 8 : 2) move_straight(sx > 0 ? 4 : 6) if !@move_succeed && sx != 0 end end -
Ok I found out! I needed to put the script in a set route block in order for the script call to make sense.