Apply Local Rotation On Input within a Given Range
Sorry if this is answered, I can't figure it out from the answers to similar questions.
I have a character holding a shield, and I want him to be able to move his shieldarm right and left to block attacks.
I have a player controller script, I access the arm gameobject, because I need to rotate the arm to make the shield move
private GameObject shieldShoulder;
Then in Update, I check for input
if (Input.GetKey("q"))
{
if (shieldShould.transform.eulerAngles.y >= -90f && shieldShoulder.transform.eulerAngles.y <= 20f)
{
shieldShoulder.transform.Rotate(0f, +1f, 0f, Space.Self);
}
}
if (Input.GetKey("e"))
{
if (shieldShoulder.transform.eulerAngles.y >= -90f && shieldShoulder.transform.eulerAngles.y <= 20f)
{
shieldShoulder.transform.Rotate(0f, -1f, 0f, Space.Self);
}
}
The shield moves for 1 second then stops. I think this is because the value of the transform is somehow not being captured and is moving too fast and the range is broken.
Any help would be greatly appreciated!
Your answer
![](https://koobas.hobune.stream/wayback/20220613001409im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Check rotation of an obstacle 0 Answers
Making an object spin on impact 0 Answers
Rotation problem: Object rotates but shouldn't 0 Answers
Rotation of game objects 0 Answers
Rotate Player w/Touch Input Controls 0 Answers