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 Yu Song Momo, which is the control script.CodeChanged.
My code is as follows:
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 inside me} else {animation. play ("walk"); // animated walking transform. lookat (vector3 (touch key_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.