- Home /
Question by
jejeserafico · Sep 08, 2012 at 04:44 AM ·
collisionrigidbodygameobjects
Make my gameobject bounce
i have a die(dice) and a button
after clicking the button, i want my gameobject to bounce and roll in a random way like playing a real dice game
here is my button code, i have a spawnpoint where the die will spawn
var SpawnPoint : GameObject;
function OnGUI()
{
if(GUI.Button(Rect(640,40,150,50), "ROLL DIE"))
{
SpawnPoint.transform.position = transform.position;
}
}
here is my bounce code:
*my function start is only for hiding my gameobject under the terrain
*my real problem here is that, the die do crazy bounces like teleporting
or what so ever crazy stuff after colliding to my background
what should i do to my codes...help me pls :(
var direction = Vector3(2, 1, 0);
function Start()
{
transform.position.y = -10;
}
function Update()
{
transform.Translate(direction * Time.deltaTime);
}
function OnCollisionEnter(theCollision : Collision)
{
if(theCollision.gameObject.name == "BackGround")
{
direction.y *= 10;
}
}
Please excuse my poor/bad English =)
Comment