September 2010
Beginner
384 pages
8h 49m
English
Now that we can detect when the heart is hitting the tray, there's no end to the fun we can have! While we're in the code, let's make a quick change to make the gameplay slightly better.
var velocityWasStored = false;
var storedVelocity : Vector3;
function OnCollisionEnter(col : Collision) {
if(col.gameObject.tag == "tray") {
Debug.Log("yes! hit tray!");
if (!velocityWasStored) {
storedVelocity = rigidbody.velocity;
velocityWasStored = true;
}
rigidbody.velocity.y = storedVelocity.y;
}
}
Save the script and test the game. You may not notice a difference at first, but we've made a clear improvement to our mechanic.
Read now
Unlock full access