Harakami lens movement and rotation, basic Unity manipulation implementation

Time:2023-10-30
  • The movement and rotation of the Harakami lens can be realized through basic Unity operations. A simple implementation is provided here.
    
    1. Lens movement
    
    You can add the following code to the camera to make the lens move back and forth, left and right, when the WASD key or arrow keys are pressed.
    public float speed = 10.0f;
    
    void Update()
    {
        float horizontal = Input.GetAxis("Horizontal") * speed * Time.deltaTime;
        float vertical = Input.GetAxis("Vertical") * speed * Time.deltaTime;
    
        transform.Translate(new Vector3(horizontal, 0, vertical));
    }
    2. Lens rotation
    
    You can add the following code to the camera to make the lens rotate according to the mouse movement to simulate the lens rotation effect in the original God.
    public float sensitivity = 5.0f;
    
    void Update()
    {
        float horizontal = Input.GetAxis("Mouse X") * sensitivity;
        float vertical = Input.GetAxis("Mouse Y") * sensitivity;
    
        transform.Rotate(new Vector3(-vertical, horizontal, 0));
    }
    3. Lens zoom
    
    If you need to realize the lens zoom effect in the scene, you can add the following code on the camera:
    public float zoomSpeed = 10.0f;
    public float minZoom = 0.1f;
    public float maxZoom = 100.0f;
    
    void Update()
    {
        float zoom = Input.GetAxis("Mouse ScrollWheel") * zoomSpeed;
        transform.Translate(0, 0, zoom);
    
        Vector3 position = transform.position;
        position.y = Mathf.Clamp(position.y, minZoom, maxZoom);
        position.z = Mathf.Clamp(position.z, -maxZoom, -minZoom);
        transform.position = position;
    }
    ``
    
    This code will allow you to zoom the camera using the mouse wheel. You can limit the minimum and maximum values that the camera can be zoomed to by adjusting the `minZoom` and `maxZoom` variables.

AI Automatic Article Writing_Free Online Original Article Generator_Juluan AI Writing Assistant

Recommended Today

uniapp and applet set tabBar and show and hide tabBar

(1) Set the tabBar: uni.setTabberItem({}); wx.setTabberItem({}); indexnumberisWhich item of the tabBar, counting from the left, is indexed from 0.textstringnoButton text on tabiconPathstringnoImage PathselectedIconPathstringnoImage path when selectedpagePathstringnoPage absolute pathvisiblebooleannotab Whether to display uni.setTabBarItem({ index: 0, text: ‘text’, iconPath: ‘/path/to/iconPath’, selectedIconPath: ‘/path/to/selectedIconPath’, pagePath: ‘pages/home/home’ }) wx.setTabBarItem({ index: 0, text: ‘text’, iconPath: ‘/path/to/iconPath’, selectedIconPath: ‘/path/to/selectedIconPath’, pagePath: ‘pages/home/home’ }) […]