Mouse movement on the screen to control the camera level, vertical rotation

Source: Internet
Author: User

usingUnityengine;usingSystem.Collections; Public classCameracontroller:monobehaviour { Public floatDistance_v;  Public floatDistance_h;  Public floatRotation_h_speed=1;  Public floatRotation_v_speed=1;  Public floatMax_up_angle = the;//the bigger the head, the higher it gets.     Public floatMax_down_angle =- -;//the smaller the head, the lower it gets.     PublicTransform Follow_obj;//player    Private floatCurrent_rotation_h;//Horizontal Rotation result    Private floatCurrent_rotation_v;//Vertical Rotation Result    voidlateupdate () {//Control Rotationcurrent_rotation_h+= Input.getaxis ("Mouse X")*Rotation_h_speed; Current_rotation_v+ = Input.getaxis ("Mouse Y")*Rotation_v_speed; Current_rotation_v=mathf.clamp (Current_rotation_v, Max_down_angle, Max_up_angle);//Limit Vertical Rotation angleTransform.localeulerangles =NewVector3 (-current_rotation_v,current_rotation_h,0f); //change position to track the target as the center of Vision, and the center of vision is always oriented to Follow_objTransform.position =follow_obj.position; Transform. Translate (Vector3.back*Distance_h, space.self); Transform. Translate (Vector3.up* Distance_v, Space.world);//y-axis upward relative to world coordinates    }}

Mouse movement on the screen to control the camera level, vertical rotation

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.