Player Turn Towards Mouse Cursor?

Status
Not open for further replies.

Sc0wly

Veteran
Veteran
Joined
Feb 13, 2017
Messages
46
Reaction score
11
First Language
English
Primarily Uses
RMMV
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.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,644
First Language
Czech
Primarily Uses
RMMV
Search for how mouse x and y are handled inside rpg_core.js. Then the event will have this one script command:
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.
 

Sc0wly

Veteran
Veteran
Joined
Feb 13, 2017
Messages
46
Reaction score
11
First Language
English
Primarily Uses
RMMV
Thanks, Poryg. Not sure if I'll have much luck, but I'll look into it. :)
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,644
First Language
Czech
Primarily Uses
RMMV
Sure thing. The mouse is called TouchInput and the methods should contain pageToCanvasX and pageToCanvasY if I remember correctly.
 

Sc0wly

Veteran
Veteran
Joined
Feb 13, 2017
Messages
46
Reaction score
11
First Language
English
Primarily Uses
RMMV
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 :/
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,644
First Language
Czech
Primarily Uses
RMMV
You can't do mouse grid coordinates, but you can do player screen coordinates.
 

Sc0wly

Veteran
Veteran
Joined
Feb 13, 2017
Messages
46
Reaction score
11
First Language
English
Primarily Uses
RMMV
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! :D
 

OgreLeg

Veteran
Veteran
Joined
Nov 23, 2017
Messages
33
Reaction score
1
First Language
English
Primarily Uses
RMMV
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.
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
8,020
Reaction score
5,332
First Language
Dutch
Primarily Uses
RMXP

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.

 
Status
Not open for further replies.

Latest Threads

Latest Posts

Latest Profile Posts

2021? I still wonder if people still doing MV than MZ more
Seeing a lot more active Ace topics recently, is it making a comeback? :o
0-7, left-to-right, top-to-bottom
As soon as I'm able to get out of bed I'm probably gonna go so hyper from being too cooped up, and burn myself out into another awful flare. lol
It makes me feel proud whenever an RM game does well. Even though I had nothing to do with it.

Forum statistics

Threads
107,627
Messages
1,031,011
Members
139,746
Latest member
Krunga
Top