Turn Player Towards Mouse Pointer on Click - Script Call

EmmaB

Veteran
Veteran
Joined
Feb 20, 2018
Messages
125
Reaction score
165
First Language
English
Primarily Uses
RMMV
Does anyone know if there is a script call that makes the player turn towards the mouse pointer when you click the screen?
Any help would really be appreciated!
 

OgreLeg

Veteran
Veteran
Joined
Nov 23, 2017
Messages
32
Reaction score
1
First Language
English
Primarily Uses
RMMV
Hey, I've researched this exact topic rather exhaustively when I was making a shooter-style action rpg. Literally, the best I found were plugins that could face me towards the mouse at all times, which was a work-around but changed the overall feel of the game.

CT Bolt's Touch Input Plugin

The only thing I've ever, ever seen that does what you're asking for is KageDesu's ABS plugin. It's an action battle system plugin that, as a side effect, turns the player towards the mouse on click. I could be wrong, but I've never seen the feature anywhere else. So I'd say start there. I just don't know what other plugins you're running or if there'd be any compatibility issues.

KageDesu's Alpha ABS

If anyone ever figures out a way to do this, I hope they speak up. From what I've seen, there is nothing that's "impossible". Just things people have or haven't done yet.
 

AdeptusUK

Veteran
Veteran
Joined
May 27, 2020
Messages
63
Reaction score
15
First Language
English
Primarily Uses
RMMV
Is this instead of the player moving? So the player just turns to face the click and you move with, presumably, the arrow keys?
 

EmmaB

Veteran
Veteran
Joined
Feb 20, 2018
Messages
125
Reaction score
165
First Language
English
Primarily Uses
RMMV
@AdeptusUK I am trying to make a game that has on screen shooting (I'm using Galv's Map Projectiles plugin for that) but I'm wanting the player to be only able to shoot in the direction the player is facing and diagonally in front.
 

AdeptusUK

Veteran
Veteran
Joined
May 27, 2020
Messages
63
Reaction score
15
First Language
English
Primarily Uses
RMMV
Right. So. The attached plugin works in a vanilla project. I'm providing it simply because no one else has provided you with a solution, that being said it is a bit of gross brute forcing using knowledge of js that I have only acquired through needing some understanding for my own projects. I suppose what I'm saying is that I am not proud of it.

Basically I have intercepted the "I've pressed something on the keyboard" event and, if the key is an arrow key, I have set the value of variable 1 = 1. In the execute move function this variable is then set back to zero. When the variable = 1 the player will move, when it does not the player will turn to face that direction. You will need to set up the plugin so that it keys off of whatever variable you want in your game.

My sincere hope is that someone good with js sees this, is horrified and provides you with something better!
 

Attachments

OgreLeg

Veteran
Veteran
Joined
Nov 23, 2017
Messages
32
Reaction score
1
First Language
English
Primarily Uses
RMMV
Starting at line 2875 in RPGcore.js I found this, which may or may not hold the key to setting something like this up.

JavaScript:
/**
* [read-only] The x coordinate on the canvas area of the latest touch event.
*
* @static
* @property x
* @type Number
*/
Object.defineProperty(TouchInput, 'x', {
    get: function() {
        return this._x;
    },
    configurable: true
});

/**
* [read-only] The y coordinate on the canvas area of the latest touch event.
*
* @static
* @property y
* @type Number
*/
Object.defineProperty(TouchInput, 'y', {
    get: function() {
        return this._y;
    },
    configurable: true
});

/**
* [read-only] The time of the last input in milliseconds.
*
* @static
* @property date
* @type Number
*/
Object.defineProperty(TouchInput, 'date', {
    get: function() {
        return this._date;
    },
    configurable: true
});

/**
* @static
* @method _setupEventHandlers
* @private
*/
TouchInput._setupEventHandlers = function() {
    document.addEventListener('mousedown', this._onMouseDown.bind(this));
    document.addEventListener('mousemove', this._onMouseMove.bind(this));
    document.addEventListener('mouseup', this._onMouseUp.bind(this));
    document.addEventListener('wheel', this._onWheel.bind(this));
    document.addEventListener('touchstart', this._onTouchStart.bind(this));
    document.addEventListener('touchmove', this._onTouchMove.bind(this));
    document.addEventListener('touchend', this._onTouchEnd.bind(this));
    document.addEventListener('touchcancel', this._onTouchCancel.bind(this));
    document.addEventListener('pointerdown', this._onPointerDown.bind(this));
};

/**
* @static
* @method _onMouseDown
* @param {MouseEvent} event
* @private
*/
TouchInput._onMouseDown = function(event) {
    if (event.button === 0) {
        this._onLeftButtonDown(event);
    } else if (event.button === 1) {
        this._onMiddleButtonDown(event);
    } else if (event.button === 2) {
        this._onRightButtonDown(event);
    }
};

/**
* @static
* @method _onLeftButtonDown
* @param {MouseEvent} event
* @private
*/
TouchInput._onLeftButtonDown = function(event) {
    var x = Graphics.pageToCanvasX(event.pageX);
    var y = Graphics.pageToCanvasY(event.pageY);
    if (Graphics.isInsideCanvas(x, y)) {
        this._mousePressed = true;
        this._pressedTime = 0;
        this._onTrigger(x, y);
    }
};


Maybe there's a way to either assign those x,y coords to a variable or even just code in a face to coords?

PS - I know you were trying not to use a plugin but just in case, Galv projectiles and KageDesu's Alpha ABS are fully compatible.
 

AdeptusUK

Veteran
Veteran
Joined
May 27, 2020
Messages
63
Reaction score
15
First Language
English
Primarily Uses
RMMV
I don't think you will be able to do this without using a plugin (sorry, I missed the post where you said you didn't want one) - you are trying to intercept a core event in the game. The js listens for that event (like a parallel event) so I don't think you could combat it with events or script commands in-game.
 

EmmaB

Veteran
Veteran
Joined
Feb 20, 2018
Messages
125
Reaction score
165
First Language
English
Primarily Uses
RMMV
Ok, I finally got the result I was wanting (with a lot of help from my dad)! :) Using a few conditional branches with script calls, I can now only shoot in the direction the the player is facing.
Note: Galv's Map Projectiles Plugin is needed for this to work.

1603698893998.png

1603698910118.png

Script Calls:
For Facing Up:
(Math.abs ($gameVariables.value(5)) <= Math.abs ($gameVariables.value(6))) && $gameVariables.value(2) <= $gameVariables.value(4);

For Facing Down:
(Math.abs ($gameVariables.value(5)) <= Math.abs ($gameVariables.value(6))) && $gameVariables.value(2) >= $gameVariables.value(4);

For Facing Right:
(Math.abs ($gameVariables.value(5)) >= Math.abs ($gameVariables.value(6))) && $gameVariables.value(1) >= $gameVariables.value(3);

For Facing Left:
(Math.abs ($gameVariables.value(5)) >= Math.abs ($gameVariables.value(6))) && $gameVariables.value(1) <= $gameVariables.value(3);

Galv's Map Projectiles script has the option to disable mouse movement.
Thanks for your help everyone. :LZSsmile::LZSsmile::LZSsmile:
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Getting work done in the hospital is a little tough :kaosigh:
Yet another custom skill animation, sometimes i waste too much time on details people will barely notice :kaocry:
Time flies by... already 1/6th of the calendar released :o

Forum statistics

Threads
105,823
Messages
1,016,723
Members
137,521
Latest member
HunterDev
Top