Unity3d to achieve the effect of "Monument Valley" distorted objects

Source: Internet
Author: User


Monument Valley, example Picture:






Note that the FBX import new project File scale shrinks and needs to be scaled up by scaling Factor
Special meshfilter material is required. Download Address: Http://pan.baidu.com/s/1jIbnQfG

The code is as follows:

Using Unityengine;
Using System.Collections;
Using System;
    public class Twistscript:monobehaviour {public float twist = 1.0f;
    public float inputsensitivity = 1.5f;
    Private vector3[] basevertices;
    Private vector3[] basenormals;
       Private Vector3 New_pos;  Update is called once per frame void Update () {twist + Input.getaxis ("horizontal") * inputsensitivity
        * TIME.DELTATIME;
        Limit twist Range if (Twist <-2) {twist =-2;
        } if (Twist > 2) {twist = 2;
        Mesh mesh = getcomponent<meshfilter> (). Mesh;
        if (basevertices = = null) {basevertices = mesh.vertices;
        } if (basenormals = = null) {basenormals = mesh.normals;
        } vector3[] vertices = new vector3[basevertices.length];
        vector3[] normals = new Vector3[basenormals.length]; for (int i = 0; i < vertices. Length;i++) {Vertices[i] = Dotwist (Basevertices[i], basevertices[i].y * twist);
        Normals[i] = dotwist (Basenormals[i], basevertices[i].y * twist);
        } mesh.vertices = vertices;
        Mesh.normals = vertices; Mesh.
        Recalculatenormals (); Mesh.
    Recalculatebounds ();
        }//produces twisted private Vector3 dotwist (Vector3 pos, float t) {Float St = Mathf.sin (t);
        float ct = mathf.cos (t);
        New_pos = Vector3.zero;
        new_pos.x = pos.x * Ct-pos.z * ST;
        new_pos.z = pos.x * St + pos.z * CT;
        New_pos.y = Pos.y;
    return new_pos;
 }
}



the effect is shown in the following figure:







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.