• Hey! Guest! The 40th (!!!) GMC Jam will take place between February 25th, 12:00 UTC to March 1st 12:00 UTC. Why not join in this very special anniversary jam! Click here to find out more!

Turn Player with Right Stick (Top Down) Question


So in my infinite wisdom (I have no idea how I did this, but I did a couple of semi coherent wild guesses) I managed to create a system where if I use my right stick my player character will look where the stick is pointing.

How it works is, is that if I aim (move my right stick into any direction), my character will face into the direction of a reticule object that is circling the player. I don't actually need to see the reticule, so I made it not draw itself. However, for future reference, I would like to know a way to make the reticule always stay a minimum distance away from the player.

Here is my code that is placed in the reticule object:

///Circle Around Player if Aiming
if !keyboard {
reticule_dist = 16;

x = obj_p1.x + lengthdir_x(reticule_dist*gamepad_axis_value(0,gp_axisrh),east);
y = obj_p1.y + lengthdir_y(reticule_dist*gamepad_axis_value(0,gp_axisrv),south); }
///End of Code

What the reticule obviously does here, is return to the center of the player if the aim stick is not used. It's not that big of a deal, since the player will face a direction if you're not aiming. The slight problem I have is that the if the player is standing still, and you stop using the aim stick, the player sometimes jolts a little to the direction of the returning reticule (EDIT: THIS JOLT IS NO LONGER AN ISSUE, SINCE I FORGOT TO REMOVE SOME KEYBOARD ACTIONS). I got this far by pretty much just subconsciously understanding how this thing works, so placing a minimum distance to the reticule from the player seems to be out of my reach, though I love exploring and I will try different things out.

While I do that, it would be great if any of you could give a simple solution to this issue. Thanks!
I would rewrite it so that you use point direction, rather than having an object that is entirely based around trying to find the direction to a point:
var gpx = gamepad_axis_value(0,gp_axisrh);
var gpy = gamepad_axis_value(0,gp_axisrv);
if (abs(gpx) > deadzone || abs(gpy) > deadzone) {
    pad_dir = point_direction(0,0,gpx,gpy);
pad_dir should end up pointing wherever the right thumbstick is pointing. No need for an invisible reticle object or worrying about length, etc. deadzone is just a variable you use to make sure that the direction isn't changed unless the controller is moved enough (you have to set it and pad_dir manually in the Create Event), a value of 0.1 for deadzone should be alright to start with, but if you find the aim is wandering, set it a little higher (and if you release the game to actual players, make sure to make the deadzone value into a setting people can change).

EDIT: This code should be in whatever object is doing the aiming, not in the reticle object. You can delete the reticle object if you implement this code.


I'll try this out, thank you.

I already set an adjustable dead zone since my controllers are very sensitive, but I did that elsewhere.