2.5D Platformer — Collectables #12

No Animations needed! Just code!

One thing I noticed through Game Dev forums, videos, and tips is that not always a GameObject has to have an animation. Instead, code is used to be mixed with complex animations or to increase performance by avoiding the Animator (specially on UI).

So, I’ve decided to manually code a simple animation for a collectable in my prototype!

Simple Move and Rotate

For the collectable, I want it to go up and down. The simplest way to do this is to use Sine waves, and adjusting the values of the frequency and amplitude to my liking.

Original Position + Direction To Move * Sine Wave through Unity’s run time

I also want it to rotate around the Y axis. With transform.Rotate and a Speed variable, it’s more than enough.

Collecting

As of right now, I don’t have a manager to track the collectables picked up by the controller. I would need to create a new Singleton script and send a pick-up event to it.

Either way, just using a Trigger Collider and OnTriggerEnter, that’d be enough to trigger the event which I set to just deactivate the Collectable GameObject.

Checks if a Controller has entered the Trigger. You wouldn’t want any object to trigger the pick up event, right?

Result

Neat! Didn’t even need the Animator, tchh.

--

--

--

Junior Unity Developer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Working with dates on SQL — Practice Example 1 (Self Join)

Can people from non-software background get into the coding profile? Yes!

C++ Datastructures and Algorithms Final Exam Solutions

Optimizing Images for the Web

Dridex Analysis

🔥 #LitePaper #Community

COFFICE STORY: Riste Kabranov, Python/Odoo developer

Data Structures — The Learning Continues

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Pablo Gómez Platón

Pablo Gómez Platón

Junior Unity Developer

More from Medium

Is technology able to save our planet from carbon dioxide?

Jim Vani — Most Effective Wealth Creation Strategy For Property Beginners

DYdX Falls from the Altar, How Can OVAL Become King in the Post-Trading Era

The Covid-19 Pandemic: A Blessing in Disguise