I looked at Yu Song MOMO's joystick. It's good, but I don't think it's comprehensive, and there are only eight directions (maybe it's the reason for setting the angle to 90 degrees ), below is a simple method for improvement. The basic operation is the same as that of Yusong MOMO, that is, the code of the control script has changed.
My code is as follows:
[Java]
Var touchKey_x = moveJoystick. position. x;
Var touchKey_y = moveJoystick. position. y;
If (touchKey_x = 0 & touchKey_y = 0 ){
If (! Animation. isPlaying)
Animation. Play ("Take 001"); // an animation in me
}
Else {
Animation. Play ("walk"); // animation for walking
Transform. LookAt (Vector3 (touchKey_x * 100000, transform. position. y, touchKey_y * 100000 ));
Transform. Translate (Vector3.forward * speed * Time. deltaTime );
}
}
Key point: I originally wanted to use Mathf. Infinity to represent this 100000, but the result is not what I want, so it is expressed with a large value.
Note: I use transform. LookAt to indicate that the object is in a certain direction. You can check the positions of the joystick and feel it for yourself.
From dlnuchunge's column