- Home /
Testing if the player is holding a direction?
I'm working on a third person stealth game. I want include a mechanic in which, if you are snapped to cover, move up to a corner, and continue holding the vague direction of the corner, you will peek around the corner. I have most of this implemented and it should work, I just don't know how to test whether the player is holding a direction or not. I will include my current implementation (although some of it might not make sense without context of the rest of the code). It currently ends in an infinite loop. If anyone has any ideas, that would be amazingly helpful. Thanks!
void PeekCover(int rotDir) { int count = 0; float rotation = Mathf.Round(closest.transform.localEulerAngles.y + closest.transform.parent.transform.localEulerAngles.y); float srotation = Mathf.Round(swapper.transform.localEulerAngles.y + swapper.transform.parent.transform.localEulerAngles.y); bool inCorner = true; Vector3 dirCheck = movement;
//check if against a wall
if(rotDir == 1)
{
if(srotation == 90)
inCorner = false;
} else if(rotDir == 2)
{
if(srotation == 270)
inCorner = false;
} else if(rotDir == 3)
{
if(srotation == 180)
inCorner = false;
} else if(rotDir == 4)
{
if(srotation == 0)
inCorner = false;
}
//end wall check
Debug.Log("hi");
if(inCorner == false)
{
if(rotDir == 1)
{
while(dirCheck == movement && count <= 50)
{
count++;
Debug.Log("count");
}
if(count >= 50)
transform.Rotate(30f * Time.deltaTime, 0f, 0f);
//rotate x by 30
while(dirCheck == movement && count >= 50)
{
if(Input.GetKeyDown("left ctrl"))
{
//switch cover to second closest
}
}
if(count >= 50)
transform.Rotate(-30f * Time.deltaTime, 0f, 0f);
//derotate
}
else if(rotDir == 2)
{
while(dirCheck == movement && count <= 50)
{
count++;
Debug.Log(count);
}
if(count >= 50)
transform.Rotate(-30f * Time.deltaTime, 0f, 0f);
//rotate x by -30
while(dirCheck == movement && count >= 50)
{
if(Input.GetKeyDown("left ctrl"))
{
//switch cover to second closest
}
}
if(count >= 50)
transform.Rotate(30f * Time.deltaTime, 0f, 0f);
//derotate
}
else if(rotDir == 3)
{
while(dirCheck == movement && count <= 50)
{
count++;
Debug.Log(count);
}
if(count >= 50)
transform.Rotate(0f, -30f * Time.deltaTime, 0f);
//rotate z by -30
while(dirCheck == movement && count >= 50)
{
if(Input.GetKeyDown("left ctrl"))
{
//switch cover to second closest
}
}
if(count >= 50)
transform.Rotate(0f, 30f * Time.deltaTime, 0f);
//derotate
}
else if(rotDir == 4)
{
while(dirCheck == movement && count <= 50)
{
count++;
Debug.Log(count);
}
if(count >= 50)
transform.Rotate(0f, 30f * Time.deltaTime, 0f);
//rotate z by 30
while(dirCheck == movement && count >= 50)
{
if(Input.GetKeyDown("left ctrl"))
{
//switch cover to second closest
}
}
if(count >= 50)
transform.Rotate(0f, -30f * Time.deltaTime, 0f);
//derotate
}
}
}
Hmm, exactly what is it that you need? Please excuse my question, I am having trouble understanding.
But I think what you're looking for is a rotation velocity. or something like that, I came across before but never used it. So like if (this GameObject Rotation Velocity == 0) { Then after that you Start a Coroutine, and count up to how many seconds you want}
Then when Coroutine reaches that limit create a Boolean called Player is Holding Direction.
And bam.
If that's not what you needed then srry about that, I'm not too far off from a beginner myself lol.
Well, I could not find anything about rotation velocity in the unity documentation. I'm not entirely sure what you're referring to therefore. I do think that you know what I'm looking for though.