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
114
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
745
Reaction score
3,938
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
114
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

Stream will be live shortly with some game development! Feel free to drop by!
it took soooo long to get character assist to work right in my game. like certain fighting games, a team mate can hop in, do an attack, then leave. it works since these are all one on one fights (usually)
Honestly. Didn't sleep for a day. ONCE
Hi! I've been working on some character sprites for my pirate themed game.
Still somewhat new to pixel art, so feedback or inputs would be appreciated ^^
TRIVIA: I love Japanese food and culture! I've never been to Japan, but someday I'm going to go to Tokyo and do some touring, including Disneyland Tokyo and DisneySea! And I even prepared myself for earthquake safety.

Forum statistics

Threads
104,259
Messages
1,005,023
Members
135,770
Latest member
Yeah_That_1
Top