Moving events by pixel instead of by grid?

I have a number of situations where it would be INSANELY handy to be able to move events around by pixel instead of by grid, and when I say "move", what I really mean is "teleport" as I don't necessarily want them traveling from one location to the next.

I've tried the janky way of doing this, mainly by taking the screen height and width, then dividing them by the number of pixels in the grid (or an approximation), then having the "Move Event" command fetch those variables.

The problem with that is that it's not exactly accurate, and it always snaps the event to the grid, which isn't what I want to have happen, either.

Is there a JS call that can move an event to pixel coords instead of grid coords, or anything else that might make this more doable? Ideally, this would happen through fetching the pixel coords from variables as well.

Thanks in advance!
Here's a pixel movement plugin. Hope it helps! https://forums.rpgmakerweb.com/index.php?threads/quasi-movement.48741/
I'm using Quasimovement for characters walking around, but the problem is that (as near as I can tell from reading the documentation), there's no way to use it to place an event at pixels X/Y using variables.

You can use the starting offsets <ox=X> <oy=Y>, but that's relative to the screen and I need to be able to set it via variable (which I forgot to mention and edited into the OP).

If there was a way to instruct it to <ox=(var23)> or something, that would be perfect...
Use the set event location event command to place them at the x and y position you want, and then use

Code:
$gameMap.event(eventId)._x += your fraction (1/2, 1/3, 0.1,...)
$gameMap.event(eventId)._y += your fraction

The event command will teleport them into position. However, modifying their x and y coordinates directly, while it allows you to make them snap off the grid, will make them slide into position akwardly. That's why you should teleport them as close as possible to the position first, if possible before the player can see it.

Note that this is in map squares, you'll have to do the math to get the pixel coordinates yourself.

Ex: you want to put the object between tiles [15,16] and [16,16], you teleport it to [15,16] with the event command and add 0.5 to _x via script call.

It's the only solution I know of without requiring a plugin.

Edit: Calculation example spoiler'd below
Spoiler
Converting pixel coordinates to grid to use in this method is easy:
Divide your coordinate by the grid size, grab the integer part. You have the grid coordinate.
Then take the %grid size of the pixel coordinate and divide it byt the grid size. You then have the rest of the coordinate.

EX: point(800,600) in a 48x48 grid is:
x: 800 / 48 = 16.
y: 600/48 = 12
teleport it to 16,12

800%48 = 32
32/48 = 0.67
600%48 = 24
24/48 = 0.5
add .67 to _x and .5 to _y.
Use the set event location event command to place them at the x and y position you want, and then use

Code:
$gameMap.event(eventId)._x += your fraction (1/2, 1/3, 0.1,...)
$gameMap.event(eventId)._y += your fraction

The event command will teleport them into position. However, modifying their x and y coordinates directly, while it allows you to make them snap off the grid, will make them slide into position akwardly. That's why you should teleport them as close as possible to the position first, if possible before the player can see it.

Note that this is in map squares, you'll have to do the math to get the pixel coordinates yourself.

Ex: you want to put the object between tiles [15,16] and [16,16], you teleport it to [15,16] with the event command and add 0.5 to _x via script call.

It's the only solution I know of without requiring a plugin.

Edit: Calculation example spoiler'd below
Spoiler
Converting pixel coordinates to grid to use in this method is easy:
Divide your coordinate by the grid size, grab the integer part. You have the grid coordinate.
Then take the %grid size of the pixel coordinate and divide it byt the grid size. You then have the rest of the coordinate.

EX: point(800,600) in a 48x48 grid is:
x: 800 / 48 = 16.
y: 600/48 = 12
teleport it to 16,12

800%48 = 32
32/48 = 0.67
600%48 = 24
24/48 = 0.5
add .67 to _x and .5 to _y.

I think I'll have to do that...

Though, since you mention plugins, I AM using Quasimovement and it does at least have the following command for setting pixel position:

Game_CharacterBase.prototype.setPixelPosition = function(x, y) {
this.setPosition(x / QuasiMovement.tileSize, y / QuasiMovement.tileSize);

Could this command be instructed to pull the x, y from variables (especially since the tilesize in this case is 1)?
Try it then:
Code:
$gameMap.event(eventId).setPixelPosition($gameVariables.value(varId1),$gameVariables.value(varId2))

If this doesn't work, I don't know. You'd have to ask Quasi himself, I don't know how his plugin works, because I don't use it.

You can find how to refer to variables and all script call equivalent of event commands in the following google doc.
Try it then:
Code:
$gameMap.event(eventId).setPixelPosition($gameVariables.value(varId1),$gameVariables.value(varId2))

If this doesn't work, I don't know. You'd have to ask Quasi himself, I don't know how his plugin works, because I don't use it.

You can find how to refer to variables and all script call equivalent of event commands in the following google doc.

It works......!

The only slight hiccup is that QM appears to be acquiring the pixel coordinates from the map instead of the screen, but that's easily remedied via adding offset values for the size of the map and the resolution.

I may as well go this route since I need QM to handle pixel-based movement anyway.

In any case, thanks so much to for your help! 🙂

Original thread: https://forums.rpgmakerweb.com/threads/moving-events-by-pixel-instead-of-by-grid.78200/