Hi, I’m new to U3d and JavaScript and trying to make a project here.
What I want to do is when a rock falls down onto the terrain, a crater generates on that spot of the terrain.
My question is when touch = true, how can I send the position of the collision to the function DeformTerrain? I know my coding has many problems, please give some suggestions. Thanks.
function OnCollisionEnter (collision : Collision)
{
var contact;
if (collision.gameObject.tag == "rock")
{
touch = true;
contact = collision.contacts[0];
thisPositon = contact.transform;
}
}
function Update ()
{
}
function LateUpdate ()
{
if (touch)
{
DeformTerrain (thisPositon);
touch = false;
}
}
function DeformTerrain (pos : Transform)
{
// generate a crater here
}