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
117
Reaction score
65
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

Sprokle Boi
Veteran
Joined
Jun 22, 2019
Messages
755
Reaction score
4,034
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
117
Reaction score
65
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

Less than a week and I can move into my new apartment and out of this bad situation. I'm so excited! Then game making power will increase. :kaoluv:
Enter the password in letters. (English subtitles)
I really tried to pull off something for halloween, but I don't feel like going on. I feel like the plot I was building was too generic, and I couldn't connect to it as I do with other projects. On the bright side, I've been working on my cosmic-puzzle project, so far I think the core mechanics are working properly, so I'll be creating some large test maps to see how it works out.
People2_5 & SF_Monster1 added!

Ami
--- X Costume ---

M.Healer: I'm wearing M.Mage's Costume.
M.Mage: I'm wearing M.Healer's Costume.
M.Knight: Why not using the Scary Costume like me,The Scary Frankenstein?
M.Healer: Err…Because we have low of Budget.
M.Mage: Yeah,right.

Forum statistics

Threads
104,602
Messages
1,007,487
Members
136,084
Latest member
TikeTenGamesOffical
Top