Unity3D standard joystick

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.