Axis Aiming Help?

O

Owen Buckley

Guest
I'm trying to use the right stick (horizontal axis only, i'm using a guitar hero controller and they only have the one axis) to move my image angle.
My stick goes between -1 and 1 and i can't figure out how to get this to work, if possible id like to have full 180 degree control (only aiming in front of you), is this even possible? if it is can someone help? any assistance is welcome and very appreciated.

Edit: I've never worked with controller inputs, i'd assume that's why i'm having a hard time.
 

devKathy

Member
Hey -

First question, are you currently receiving input from the stick?

Second question, am I correct in assuming that we want to aim in some sort of arc that's "in front of" the player, as in a weapon? What perspective are we using here exactly, top down like in GTA?
 
O

Owen Buckley

Guest
Hey -

First question, are you currently receiving input from the stick?

Second question, am I correct in assuming that we want to aim in some sort of arc that's "in front of" the player, as in a weapon? What perspective are we using here exactly, top down like in GTA?
one, yes i am receiving input from the stick,

two, im making a platformer, so imagine mario holding a gun and moving the right stick left or right would move it up or down, preferably only between 90 degrees and 270 degrees.

if needed i can upload pictures. I followed a platformer video series for school and am working on modding it.
 

devKathy

Member
Awesome on number 1! Good to hear there's not a problem with the connection or anything like that; that can be hard to deal with. Could even have broken wires lol, I know I have. :)

On number 2, notice we are dealing with two different ranges of numbers. A good analogy here is converting inches to feet, or centimeters to meters. 12 inches represents exactly one foot, and 100 centimeters represents exactly one meter.

Now, the number line distance between -1 and 1 is 2, yeah? What we wanna do is convert to the scale of 90 and 270; those two have a number line distance of 180, as you mentioned. On the scale of distance 2, incrementing by about .011 is equivalent to incrementing by one degree on the distance 180 scale.

2/180 = 0.011
0.011 * 180 = 2

So we are simply scaling by a multiplier. We start at -1, and add .011 until we are 2 away from our start position. If you know your algebra, this is just a linear change, where x is degrees, and y is stick input.

y = mx + b
y = .011x - 1

Let me know if that makes sense! :D
 
O

Owen Buckley

Guest
Awesome on number 1! Good to hear there's not a problem with the connection or anything like that; that can be hard to deal with. Could even have broken wires lol, I know I have. :)

On number 2, notice we are dealing with two different ranges of numbers. A good analogy here is converting inches to feet, or centimeters to meters. 12 inches represents exactly one foot, and 100 centimeters represents exactly one meter.

Now, the number line distance between -1 and 1 is 2, yeah? What we wanna do is convert to the scale of 90 and 270; those two have a number line distance of 180, as you mentioned. On the scale of distance 2, incrementing by about .011 is equivalent to incrementing by one degree on the distance 180 scale.

2/180 = 0.011
0.011 * 180 = 2

So we are simply scaling by a multiplier. We start at -1, and add .011 until we are 2 away from our start position. If you know your algebra, this is just a linear change, where x is degrees, and y is stick input.

y = mx + b
y = .011x - 1

Let me know if that makes sense! :D

Yes that makes sense, i just can't think of how i would use that to change my image angle. Sorry in advance for lack of experience, i've only just begun using GameMaker at the start of December and this is my first time using controller inputs.
 

devKathy

Member
No worries! It's good you're taking an interest in this topic. We all start from somewhere! :)

Let's see how we can get an angle out of this. We could do something like the following:

1) Add 1 to the controller input so that we won't have to deal with any negative numbers, store the result in a variable like inputPlusOne.
2) Divide inputPlusOne by .011, store the result in a variable like scalingResultFloat
3) Take the floor of scalingResultFloat, store in something like scalingResultInteger.
4) Reduce the value of scalingResultInteger if it exceeds 180.
5) For an input to image_angle, we can just add scalingResultInteger to the base angle, or in this case 90 degrees.

One way to think about why this works is: we have a general number about what % change we want in the angle. The user gives us this with the stick. We know what we want -1 and 1 to represent, and we want to be able to evenly add the same value 180 times to get from one end of the scale to the other.

As with many control systems, you'll find that basic linear math is super applicable here. This is even the case with robots. :cool::D
 
Top