How to add or subtract 1 from the player's X or Y axis depending on direction?

shadowllp

Warper
Member
Joined
Sep 27, 2020
Messages
3
Reaction score
0
First Language
English
Primarily Uses
RMMV
I'm attempting to create an ability usable outside of combat that applies to the tile in front of the player.
RPGMV_QNOu8l8j2T.png
So okay, I have this bit that runs whenever I activate the ability. It checks the player's location & direction, moves in an event, and then plays a particle effect on it. Currently, this just plays the event on the player.

How do I say to RPGmaker, "i'm facing right, so add 1 to the variable storing X axis (in this case 0019), and if I'm facing left, -1"? So that way the event gets moved to the tile in front of the player, instead.
 

CHKNRAVE

Surprisingly not sponsored by Yanfly.
Veteran
Joined
May 11, 2020
Messages
126
Reaction score
68
First Language
French
Primarily Uses
RMMV
There's a condition in the condition submenu that lets you check if the player is facing a certain direction. Put 4 of those, one for each direction, and edit the variables accordingly.

Note: if you use else, you can do it with 3 conditions.
 

ImaginaryVillain

One With The Particle
Veteran
Joined
Jun 22, 2019
Messages
772
Reaction score
4,328
First Language
Absurdism
Primarily Uses
RMMV
If you want to do it in the editor... Set your X coordinate to be equal to ..
JavaScript:
$gameMap.roundXWithDirection($gamePlayer.x, $gamePlayer.direction());
And set your X coordinate to be equal to...
JavaScript:
$gameMap.roundYWithDirection($gamePlayer.y, $gamePlayer.direction());
You no longer need the player direction, as this already checks for that and adjusts the X/Y for direction.

You can also do a script command...
JavaScript:
let x = $gameMap.roundXWithDirection($gamePlayer.x, $gamePlayer.direction());
let y = $gameMap.roundYWithDirection($gamePlayer.y, $gamePlayer.direction());
$gameMap.event(this._eventId).setPosition(x, y);
...inside of the event in question, or of course you can replace this._eventId with the actual event ID number to use it from another event/common event.
 
Last edited:

shadowllp

Warper
Member
Joined
Sep 27, 2020
Messages
3
Reaction score
0
First Language
English
Primarily Uses
RMMV
There's a condition in the condition submenu that lets you check if the player is facing a certain direction. Put 4 of those, one for each direction, and edit the variables accordingly.

Note: if you use else, you can do it with 3 conditions.
How would I go about editing the variables accordingly? This is the part that's stumping me. Like, I have the coords of the player, but I then want to find out what the tile is in front of the player. I don't know what to add/subtract here from the coords, or how to create that number.
 
Last edited:

CHKNRAVE

Surprisingly not sponsored by Yanfly.
Veteran
Joined
May 11, 2020
Messages
126
Reaction score
68
First Language
French
Primarily Uses
RMMV
First, set up 2 variables for the coordinates of the tile in front of the player. Set them as the player's Map X and Map Y.

If the player is facing down, the Y coordinate increases by 1.
If the player is facing left, the X coordinate decreases by 1.
If the player is facing right, the X coordinate increases by 1.
If the player is facing up, the Y coordinate decreases by 1.

And that's how you get the coordinates of the tile in front of the player. Thanks to that, you can use the "Set Event Location" command (near the top-left in the 2nd page of the event menu) to place an event right in front of the player. I'm guessing you're trying to place a bomb, given that you call for a common event named "kaboom".

If you want to avoid placing an event inside a wall, you may be interested in the "Get Location Info" command in the 3rd page of the event menu (Map section).
From there, you can set a temporary variable as the region ID of the tile whose coordinates are those you just obtained, and then you just check if that temporary variable is equal to a specific value. If that's the case, cancel the placement.
The little extra work you'll have to put in is to go into the R tab in the map elements panel, select the number corresponding to the region ID you picked right before as the condition, and place that number on any tile the event on wall tiles or anywhere the event shouldn't be placed. Do that on any map where the event can be placed, and that's set up.
 

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

Latest Threads

Latest Profile Posts

So I'm practicing ITC with a spirit box, and decide to try to contact my deceased soulmate. It actually gave me multiple identifiers. Me, still a bit skeptical, asked aloud "Fine but does he still love me?" and the box spoke and printed the word "Forever" at the same time. Been a mess of tears since. :kaocry:
Been scratching away at my game and making progress, but just had a revelation. I'm working in full screen and adjusting all my pictures accordingly, but will they resize if someone's screen is smaller?? I hope this doesn't turn out to be a problem later.
Why is there so much month left at the end of money? D=
Hello humans! How goes your day in this journey of living? I hope it is good, for I am human like you, and I am feeling great! Worship the altar.

Forum statistics

Threads
105,627
Messages
1,015,074
Members
137,288
Latest member
GmOcean
Top