- Home /
On screen virtual joystick not updating
Basically I'm making an android game with a on screen virtual joystick from this free pack:
https://assetstore.unity.com/packages/tools/input-management/joystick-pack-107631
I'm having an issue where the animation to my character changes only once while at the same time the enum for direction checking updates normally.
Example, I move my joystick left, animation goes left, enum is left. I move my joystick right without lifting my thumb, animation stays left, enum is right.
Anyone know why?
Edit:
this is the enum that handles directions:
public enum DirectionFace
{
Up,
Down,
Left,
Right,
Idle
};
public enum State {
Positive,
Negative
}
this is the update code:
horizontal = joystick1.Horizontal;
vertical = joystick1.Vertical;
if (horizontal > 0)
stateH = State.Positive;
else
stateH = State.Negative;
if (vertical > 0)
stateV = State.Positive;
else
stateV = State.Negative;
switch (stateH) {
case (State.Positive):
switch (stateV) {
case (State.Positive):
if (horizontal > vertical)
direction = DirectionFace.Right;
else
direction = DirectionFace.Up;
break;
case (State.Negative):
if (horizontal > Mathf.Abs(vertical))
direction = DirectionFace.Right;
else
direction = DirectionFace.Down;
break;
}
break;
case (State.Negative):
switch (stateV)
{
case (State.Positive):
if (Mathf.Abs(horizontal) > vertical)
direction = DirectionFace.Left;
else
direction = DirectionFace.Up;
break;
case (State.Negative):
if (Mathf.Abs(horizontal) > Mathf.Abs(vertical))
direction = DirectionFace.Left;
else
direction = DirectionFace.Down;
break;
}
break;
}
if (horizontal == 0 && vertical == 0) {
direction = DirectionFace.Idle;
}
switch (direction)
{
case (DirectionFace.Up):
animator.SetInteger("Direction", 4);
break;
case (DirectionFace.Down):
animator.SetInteger("Direction", 1);
break;
case (DirectionFace.Left):
animator.SetInteger("Direction", 2);
break;
case (DirectionFace.Right):
animator.SetInteger("Direction", 3);
break;
case (DirectionFace.Idle):
animator.SetInteger("Direction", 0);
break;
}
Your answer
Follow this Question
Related Questions
FPS Camera rotates on Z when using a joystick 0 Answers
Why is my touch joystick "sticking"? 2 Answers
How do I use android bluetooth controller in unity? 7 Answers
Mobile joystick is not working in unity 2018.1 only jump button works 0 Answers
How can I able to get the Joystick movement values (Axis 6 and 7 ) in Android ..?, 0 Answers