imac2018-3d / StoneEdge

The game's main repo.
MIT License
0 stars 1 forks source link

Game Freezing #30

Closed firegreen closed 6 years ago

firegreen commented 6 years ago

Quoting @yoanlcq in #5:

Freeze entities (a.k.a ZA WARUDO (nobody's ever gonna get this reference))

Required by the pause menu, but also by cinematics. We need to be able to "stop time" for a given set of entities, which means three things:

Every component in Unity has a SetActive(bool) method supposed to do exactly that, but we need proof.
To find all GameObjects that have a given component, we can use FindObjectsOfType<MyComponent>(). This way, we can grab all enemies, then call SetActive(false) on their RigidBody, animator, etc.
The prototype's purpose would be to prove that this actually works because I'm not 100% sure myself.

yoanlcq commented 6 years ago

Just a heads-up: I'm working on this this morning, because it looks easy to do - Luan is on a plane and won't get back to Paris before 2 days or so.

yoanlcq commented 6 years ago

Solution

My latest changes add a Frozen component, and associated extension methods to GameObjects.

By just using Se or being in the Se namespaces, all GameObjects are granted to ability to be frozen and de-frozen via extension methods Freeze(), Defreeze() and IsFrozen().
Behind the hood, these methods just attach or detach a Frozen component to the GameObject.

As long as a GameObject has a Frozen component, its Rigidbody is frozen. When the Frozen component is destroyed, the Rigidbody is restored.

Freezing sets of objects

If we say that all enemy GameObjects have an Enemy component, then we can freeze them all like so : (untested)

using System.Linq;
// ....
FindObjectsOfType<Enemy>().ForEach(e => e.Freeze());

Freezing specific objects

The FrozenTest component could be slightly improved to be a general-purpose component that can be attached to any GameObject, for automatic freezing when pressing some key (possibly using InputActions for getting the pause button).

The future

Frozen only freezes Rigibody components. It should also freeze other kinds of components in the future, such as whatever component is used for animation.

yoanlcq commented 6 years ago

I'll be closing this because it's essentially done now.
Future improvements will only depend on scripts we haven't written yet.