0
\$\begingroup\$

d platformer arena like game. Right now I have it so a reticle moves around the player based on a controller's right stick's horizontal movement using the rotate around function and while it works great on keyboard on it is funky on controllers since you have to hold it left to rotate counter clockwise and right to make it rotate clockwise. I've been working on changing this for well over a month and a half. I've tried coding it myself and then googling it like crazy but I came up with nothing. the input they give you based on vertical and horizontal is what perplexes me the most. in the debugger comes up like this from a debug.log when tilting it up- "H: 0.02528, V: -.9874454". Which makes sense but when going to the top right it looks like "H: 0.7592, V: -.842965". That's the part that confuses me. I can't find a way to use this data in any of the functions I have experience with and experimenting with new ones has gone nowhere. Any suggestions or ideas would help me greatly and would be even more appreciated!

ReticleInfo

Based on the above image I want my reticle to be placed in a spot on it's orbit around a player's center based on the right stick's position on the controller. So if I completely titled up my stick the reticle goes up but if I release it stays there. Then if I tilt it to the left bottom corner it will "teleport" there without moving along the orbit. So think of old school twin stick shooters where you can aim instantly in the direction of your choice.

This is my old code that used rotate around that slowly makes the reticle orbit as you hold the stick constantly left or right. I added a new axis called AV which is for vertical instead of just horizontal so now I just need a way to use these together somehow.

void AimControllers() 
{
    if (currentControllerAimAxisH != null)
    {
        AH = Input.GetAxis (currentControllerAimAxisH);
        if (Mathf.Abs (AH) > stickTol) 
        {
              reticle.transform.RotateAround(this.transform.position,new Vector3(0,0,-AH),orbitAngle);
        }
    }
}
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

I figured it out. I was going about it all wrong. It's not perfect due to how unity handles analog sticks but here's the code.

void AimControllers ()
{
    if (currentControllerAimAxisV != null && currentControllerAimAxisH != null)
    {
        AV = Input.GetAxis (currentControllerAimAxisV);
        AH = Input.GetAxis (currentControllerAimAxisH);

        //first make sure both stick vals are higher than the tolerance
        if((Mathf.Abs (AH) > stickTol || Mathf.Abs (AV) > stickTol))
        {

            //now check if both together are greater than one (1) so either one stick 
            //is at max or both are close to the minimum tolerance
            if ((Mathf.Abs (AH) + Mathf.Abs (AV)) > 1) 
            {
                reticle.transform.localPosition = new Vector3 (AH * aimScale, -1 * AV * aimScale, 0);
            }

        }
    }
}

enter image description here

The green shape is how the aiming will work not the black circle because the stick stays at 1 too long even when not directly up so it creates a flat area when on stick is at 1. That's another reason why my other attempts failed. I also didn't need the orbit function at all. I just needed to set the values at what the axis gives me and negate Y since it's inverted then scale it so it can be as close as to the max range when it's not entirely there but at least at a minimum max value of when the stick is diagonal.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .