I have created a twisted plane by adjusting the vertices of the mesh in a plane object. I am trying to make other game object going over it smoothly, i.e. making full surface contact with the plane and with local y axis in the same direction as the plane’s normal. Here is what I have for now:
As you might see from the image above, the game object, which is a cube, is rolling over the curved plane surface instead of sliding over it. How to prevent such undesired rolling? Here is the script I have for the cube now:
using UnityEngine;
using System.Collections;
public class CubeControl2 : MonoBehaviour {
private Rigidbody rb;
void Start () {
rb = GetComponent<Rigidbody>();
}
void Update () {
rb.velocity = new Vector3(0, 0, -1);
Vector3 gravity = new Vector3(-transform.localPosition.x, -transform.localPosition.y, 0);
rb.AddForce(gravity);
}
}
And here is the script I used to twist the plane:
void Awake()
{
Mesh PlaneMesh = GetComponent<MeshFilter>().mesh;
Vector3[] vertices = PlaneMesh.vertices;
for (int i = 0; i < 11; i++)
{
for (int j = 0; j < 11; j++)
{
if (j < 5)
{
vertices[i * 11 + j].y = vertices[i * 11 + j].x * Mathf.Sin(Mathf.Deg2Rad * 18 * i);
vertices[i * 11 + j].x = vertices[i * 11 + j].x * Mathf.Cos(Mathf.Deg2Rad * 18 * i);
}
else if (j > 5)
{
vertices[i * 11 + j].y = vertices[i * 11 + j].x * Mathf.Sin(Mathf.Deg2Rad * 18 * i);
vertices[i * 11 + j].x = vertices[i * 11 + j].x * Mathf.Cos(Mathf.Deg2Rad * 18 * i);
}
}
}
PlaneMesh.vertices = vertices;
GetComponent<MeshCollider>().sharedMesh = PlaneMesh;
}
What should I change?