Hello all! I was just wondering if anyone knows of a way to craft a parallel event that causes the player character (on the overworld) to always turn toward the cursor. Either that or turn the player toward the current cursor position on click. Thank you for any help you can provide.
Player Turn Towards Mouse Cursor?
RPG Maker MV SupportSearch for how mouse x and y are handled inside rpg_core.js. Then the event will have this one script command:
I would have helped more precisely, but right now I don't have a computer, so cannot construct the precise script.
Code:
var x = $gamePlayer.screenX() - the mouse x;
var y = $gamePlayer.screenY() - the mouse y;
Then:
if (Math.abs (x) >= Math.abs(y)) x > 0 ? $gamePlayer._direction = 6 : $gamePlayer._direction = 4;
else y > 0 ? $gamePlayer._direction = 8 : $gamePlayer._direction = 2;
I would have helped more precisely, but right now I don't have a computer, so cannot construct the precise script.
Thanks, Poryg. Not sure if I'll have much luck, but I'll look into it. 🙂
Sure thing. The mouse is called TouchInput and the methods should contain pageToCanvasX and pageToCanvasY if I remember correctly.
So I'm not having much luck. I can't write a script myself (don't currently have the knowledge). What I am able to do is create parallel events which define the player's xy (grid) coordinates as variables which can be used for various things. I've also defined the mouse cursor's xy (pixel) coordinates as variables, which is extremely useful for many game mechanics that I'm not currently using. I could explore some more possibilities if I knew how to store the cursor's xy grid coordinates in variables. Then I could attempt to make a conditional branch that compares player grid position that that of the mouse cursor and reacts accordingly. No luck so far though :/
You can't do mouse grid coordinates, but you can do player screen coordinates.
Ah, nice. I was able to do what you recommended. I'll have to experiment a bit more to see if I can use these variables in the way I described earlier and whether the behavior looks correct on screen. I'm hopeful now though. Thanks for the advice, Poryg! 😀
So did this work? I've been scouring the net for 7 hours on how to do this and this post is the closest I've come. Face direction of mouse cursor or face direction of mouse click. I've tried doing it a few different ways by getting the X/Y of both player and touch input but I can't seem to get it right.
OgreLeg, please refrain from necro-posting in a thread. Necro-posting is posting in a thread that has not had posting activity in over 30 days. You can review our forum rules here. Thank you.
Closing this.
Original thread: https://forums.rpgmakerweb.com/threads/player-turn-towards-mouse-cursor.97697/