Skip to main content

Schmeechee

A class in Root.Township, Alta.Intelligence.

The schmeechee mushroom critter: a physics creature that steers itself with forces, plants itself to sleep and can be picked up. Server runs the AI; settings come from a MushroomCritter component.

Constructors​

MemberWhat it is
Schmeechee()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

11 private and internal fields
MemberWhat it is
private MethodSync embedNetwork sync that tells clients to play the embed animation.
private AnimatedBool groundedBoolBacking field for GroundedBool, the networked "Is Grounded" animator bool. Set on the server.
private static Logger loggerClass logger. Not used in this build.
private ActionComponentSet passiveActionsThe action set the critter starts with and goes back to when dropped.
private static Dictionary<ActionComponentSet, ActionSet<Schmeechee>> passiveActionSetMapStatic cache of the action set built from each passive set asset.
private Pickup pickupBacking field for Pickup.
private AnimatedTrigger popTriggerBacking field for PopTrigger, the networked "Pop" trigger.
private AnimatedFloat runSpeedBacking field for RunSpeed, the networked "Run Speed" float.
private MushroomCritter settingsBacking field for Settings, the critter's MushroomCritter tuning.
private AnimatedBool sleepingBoolBacking field for SleepingBool, the networked "Is Sleeping" bool.
private float turnForceStored turning force built up by Steer and RandomSteer and applied by Turn.

Properties​

MemberWhat it is
AnimatedBool GroundedBool { get; }Synced animator bool "Is Grounded".
bool IsGrounded { get; private set; }Whether a short ray down from the critter hits the floor. Updated each physics step while free.
bool IsUpsideDown { get; private set; }Whether it is not grounded, facing down and its head touches the floor.
Pickup Pickup { get; }The critter's Pickup. Picking it up stops its AI until dropped.
AnimatedTrigger PopTrigger { get; }Synced animator trigger "Pop".
AnimatedFloat RunSpeed { get; }Synced animator float "Run Speed".
MushroomCritter Settings { get; }The MushroomCritter movement settings.
AnimatedBool SleepingBool { get; }Synced animator bool "Is Sleeping".

Methods​

MemberWhat it is
IEnumerator ClientEmbed() (iterator)Client: animates the sink-into-ground offset. In this build it evaluates the curve at time 0 only.
override void Initialize()Sets up the synced embed message.
override void InitializeAsServer(SpawnData spawnData)Server: grabs the animator values, hooks pickup and drop, and makes the rigidbody dynamic.
void RandomSteer(float strength = 1)Adds a random amount to the stored turn force, scaled by strength.
void SendEmbedToClient()Server: tells clients to play the planting animation.
void StayUpright()Adds torque to turn the critter upright. Called when it is not acting.
void Steer(Vector3 target, float multiplier)Builds turn force towards a target, or away from it with a negative multiplier.
void Turn()Applies the stored turn force as torque, clamped to the settings' max.
protected override void InitializeAi()Uses the passive action set (cached per set) for the action decider.
protected override void InitializeStatic()Resets the shared cache of passive action sets.
7 private and internal methods
MemberWhat it is
private bool CheckGrounded()Raycasts down from the critter along its own up axis to see if it's on the floor.
private bool CheckUpsideDown()When the critter's up points mostly down, raycasts from its head to see if it's lying on its back.
private void CritterUpdate()Empty in this build.
private void Dropped(Interactable arg1, Interactor arg2)When dropped, gives the decider back its passive set.
private void Embed(IPlayer player, Stream stream)Network handler (CreatureStateChanged) that plays the burrow animation on remote clients.
private void FixedUpdate()While free and not held, updates IsGrounded, IsUpsideDown and the grounded animator bool, and keeps it upright when idle.
private void PickedUp(Interactable arg1, Interactor arg2)When grabbed, clears the decider's set, cancels the current action and marks it not grounded.