Friday, February 17, 2017

Day 12: Collecting the Pick Up objects

To make the player collect the objects, I needed to add a script that detects when the ball collides with the Pick Up objects and makes the Pick Up object disappear. This script (below) causes the pick up object to disappear when the ball touches it. That way, the ball won't bounce off of it.
Now, this script doesn't do anything by itself, since the pick up objects also have to "agree" with the ball's code. The ball is looking for an object with a tag of "Pick Up". The pick up objects currently don't have that tag. So, to fix that, I simply add a tag to the main prefab.

Now the object should "agree" with the ball's code. One more thing I had to do is make the pick up objects into "triggers".

Now to test it out.

It works! Now, to minimize the amount of resources used (number of calculations), I added a "Rigid Body" component to all of the Pick Up objects, and selected "is kinematic".

For Future Reference
-Use Gravity: self explanatory. gravity affects the object.
-Is Kinematic: The object isn't moved by physics forces, ie. Gravity or collisions. It can only be affected by transformations (movement scripts, for example)
-Freeze position: Keeps the object in that position indefinitely (unless disabled by a script). The object does not react to physics forces, and can not be moved with scripts before being disabled.

Next class I will add a score system.

No comments:

Post a Comment