Turn player towards event

Tanarex

Scrub
Veteran
Joined
Sep 14, 2014
Messages
468
Reaction score
306
First Language
English
Primarily Uses
RMVXA
I'm trying to get a player to turn towards an NPC. I looked at set move route but it doesn't have that option. I have a trapdoor spider event. The character jumps back when he touches its cobwebs and hears a screech. The web can be touched from any of the four directions. Then a giant spider pops out. I want them to face the spider. Any suggestions?
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
If the player faces the web when touching it, and then jumps back, wouldn't they already be facing the spider? Or does the spider pop out from somewhere other than the web?

I would do a Set Move Route on the spider to make it turn towards the player, and then do a Set Move Route on the player, with a script call to
Code:
set_direction(10 - $game_map.events[id])
where id is the event id of the spider, with no leading zeros.

This will make the spider face the player, and then make the player face 180 degrees to the spider's facing direction). So if the spider is facing up, the player will be facing down, and if the spider is facing right, the player will be facing left.

If you try it and it doesn't work, please give a screenshot of your event showing that script call, a screenshot of the spider event, and tell us what the error message is. When you do your screenshots, include the whole event window, not just the list of commands, because I'll need to see more than just the commands.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
sorry - that was only half complete.

Code:
set_direction(10 - $game_map.events[id].direction)
I would expect the first error "undefined local variable or method 'id'" to happen if you had entered the code exactly as I had it, without replacing id with the event number.
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,248
Reaction score
1,250
First Language
Spanish
Primarily Uses
RMVXA
$game_player.turn_toward_character($game_map.events[eventID][1])

events are characters by definition.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
VX doesn't have turn_toward_character - only turn_toward_player.
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,248
Reaction score
1,250
First Language
Spanish
Primarily Uses
RMVXA
Code:
def turn_toward_character(character)
    sx = distance_x_from(character.x)
    sy = distance_y_from(character.y)
    if sx.abs > sy.abs
      set_direction(sx > 0 ? 4 : 6)
    elsif sy != 0
      set_direction(sy > 0 ? 8 : 2)
    end
  end
turn_toward_player implies turn_toward_character(player)
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
Yes, but that function is not in VX by default. It was only expanded in Ace. I provided a way to do this that doesn't require script mods.

Also, is this valid?
$game_map.events[eventID][1]

Doesn't $game_map.events[n] return an event, rather than an array?
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,248
Reaction score
1,250
First Language
Spanish
Primarily Uses
RMVXA
$game_map.events is a hash.
I remembered somebody pointing out that events[id] would return a pair, so x[1] would return the actual event.

IDK, if events[id][1] doesn't work, just remove the [1]

(I always get that mixed up somehow)
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
ah yeah. When you do $game_map.events[id] you're getting the event. But when you do $game_map.events.for_each you're getting the key/value pair. That one has tripped me up a few times in the past as well.
 

Tanarex

Scrub
Veteran
Joined
Sep 14, 2014
Messages
468
Reaction score
306
First Language
English
Primarily Uses
RMVXA
I screwed up again. This was supposed to be in vx ace. Not vx. I blame my ADD. Which is prolly why this isn't working.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
then in a move route, do a script call with this:

Code:
turn_toward_character($game_map.events[id])
replacing id with the spider's event id, with no leading zeros.

The code I originally gave you would work in VX as well as Ace, but did you put the .direction at the end as per my second post?
 

Tanarex

Scrub
Veteran
Joined
Sep 14, 2014
Messages
468
Reaction score
306
First Language
English
Primarily Uses
RMVXA
Still can't get it to work. I tried the snippet posted by gstv87 too.
 

Attachments

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,248
Reaction score
1,250
First Language
Spanish
Primarily Uses
RMVXA
$game_player.turn_toward_character(event)

if you're on an event, you need to turn *the player* towards the event.
if you just write "turn_toward_character", you're in the event's space.
"turn_toward_character(id)" implies "self.turn_toward_character(id)", "self" being the event you are writing from.

when using move routes within the GUI tool, always mind the object space you're writing from.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
If you do it the above way, you could just do $game_player.turn_toward_character(self) if the event you're putting the move route on is the spider.

You could also do it as a second move route and select the player from the drop down list, rather than the event.
 

Tanarex

Scrub
Veteran
Joined
Sep 14, 2014
Messages
468
Reaction score
306
First Language
English
Primarily Uses
RMVXA
That worked Shaz. Thank you!
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD

Forum statistics

Threads
105,868
Messages
1,017,072
Members
137,578
Latest member
JamesLightning
Top