# TWA. Interactions in the Orangery mechanic
**Where**: [[DESIGNS/ToyWorldsAtlas/Orangery_Doc|Orangery_Doc]]
**Related**: [[DESIGNS/ToyWorldsAtlas/TWA_VFX_Doc|TWA_VFX_Doc]]
**Requirement**: Atlas Prefab (with RigidBody2D)
## ToDo
- [-] Research fitting VFX
- [ ] B&B -> Orangery petals also change colour to purple
- [ ] D&D -> bubbling sound
*Refactoring*:
- [ ] Instead of GameObject.Find, make an EffectController.gameObject with public variables
## Concept
(1) Atlases of the same type interact between each other. Each type interacts with its type in a same way which is different from the interaction between two or more atlases of another same type. E.g., [[DESIGNS/ToyWorldsAtlas/AtlasA_Doc|A]] & [[DESIGNS/ToyWorldsAtlas/AtlasA_Doc|A]] interacts differently, from B & B.
(2) Atlases of different types interact with each other differently. E.g., A & B interact in a different way than A & C, or B & C.
**Problem**: the variation of interaction needs to be limited due to the scope creep
### Methodology
- Tags + Colliders
- Visual Effects or particle systems, or physics -- see [[DESIGNS/ToyWorldsAtlas/TWA_VFX_Doc]]
- When the player clicks on the atlas in the Orangery, they can control its movement and collide it with other atlases as they want
### Effects
- CD-ROM-ish glow ([article](https://www.alanzucconi.com/2017/07/15/cd-rom-shader-2/?utm_source=chatgpt.com))
- Ripple distortion effect ([tutorial](https://www.youtube.com/watch?v=ajbNS8mncRo) -- URP required)
- Shadow trail
- More sounds
- More orangery UI-related effects
- Dates on branches change to the future (e.g. 2077 or 2049) or historical dates
- Grass changes colour and text
- The flower gains additional petals of other colours, and they rotate together ([[DESIGNS/ToyWorldsAtlas/AtlasH_Doc|Radiolaria]]?)
- Background changes colour / texture
- Waves
- The atlas repeats itself, similar to shadow, but radial
- Or an implosive wave: contours containing smaller contours. They decrease inside the atlas, revealing it further
| Stts | Participating<br>Atlases | Effect | Reference |
| :--- | :----------------------- | ---------------------------------- | ------------------------------------------------------------------ |
| | A & A | Little beetles crawl sideways | |
| ✅ | B & B | RANGERY.text glows,<br>Leaves move | |
| ✅ | C & C | Sparcles (stars) | |
| | D & D | Water bubbles & sound | [xOctoManx (YouTube)](https://www.youtube.com/watch?v=ajsA6vWBhKI) |
| Participating<br>Atlases | Effect |
| ------------------------ | ------------------------------------------------------------------------------- |
| A & B | |
| A & C | |
| A & D | |
| B & C | Second Orangery flower's petal (scale++). A more red tint of a tangerine colour |
## Code
### C & C (for a template)
```cs
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class Interact_C : MonoBehaviour
{
// Particle effects prefabs
public GameObject sparkPrefab; // for Atlas C + Atlas C
private GameObject sparkPrefabInst;
private void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.tag == "C_Atlas") // C
{
Vector2 contactPoint = col.contacts[0].point;
GameObject sparkPrefabInst = Instantiate(sparkPrefab, contactPoint, Quaternion.identity);
sparkPrefabInst.name = "C_C_effect";
}
}
private void OnCollisionExit2D(Collision2D col)
{
if (col.gameObject.tag == "C_Atlas") // C
{
DestroyEffects("C_C_effect", 1f);
}
}
private void DestroyEffects(string effectName, float duration)
{
GameObject[] collisionEffects = FindObjectsOfType<GameObject>()
.Where(go => go.name == effectName)
.ToArray();
for (int i = 0; i < collisionEffects.Length; i++)
{
if (i == collisionEffects.Length - 1)
Destroy(collisionEffects[i], duration); // the last effect is destroyed with a delay
else
Destroy(collisionEffects[i]); // all effects before last are destroyed immediately
}
}
}
```
### PlayerAtlasController
**From** Atlas_InOrangery.cs (See [[DESIGNS/ToyWorldsAtlas/Orangery_Doc|Orangery_Doc]])
- OnMouseDown (Atlas's clicked) -> Add PlayerController.cs
- For all game objects in the scene -> if has PlayerController.cs -> delete PlCo.cs
- OnMouseDown (on another atlas) -> Add PlayerController.cs to another
```cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerAtlasController : MonoBehaviour
{
private Rigidbody2D atlRig;
private void Start()
{
atlRig = gameObject.GetComponent<Rigidbody2D>();
}
// PLAYER MOVES AVATAR
private void PlayerMovesAtlas()
{
if (Input.GetKeyDown(KeyCode.W))
{
atlRig.velocity = new Vector3(0, 5, 0);
}
if (Input.GetKeyUp(KeyCode.W))
{
atlRig.velocity = new Vector3(0, 0, 0);
}
if (Input.GetKeyDown(KeyCode.S))
{
atlRig.velocity = new Vector3(0, -5, 0);
}
if (Input.GetKeyUp(KeyCode.S))
{
atlRig.velocity = new Vector3(0, 0, 0);
}
if (Input.GetKeyDown(KeyCode.A))
{
atlRig.velocity = new Vector3(-5, 0, 0);
}
if (Input.GetKeyUp(KeyCode.A))
{
atlRig.velocity = new Vector3(0, 0, 0);
}
if (Input.GetKeyDown(KeyCode.D))
{
atlRig.velocity = new Vector3(5, 0, 0);
}
if (Input.GetKeyUp(KeyCode.D))
{
atlRig.velocity = new Vector3(0, 0, 0);
}
FixRotation();
}
private void FixRotation()
{
gameObject.GetComponent<Transform>().rotation = Quaternion.Euler(0, 0, 0);
}
private void Update()
{
PlayerMovesAtlas();
}
}
```
![[atlas.borders]]