ScrewSwitch¶
A crank switch actuated by Vi's Beemerang Toss with an analog actuation that needs to be held for a certain period before being fully actuated. The angles of rotation when actuated, the rate of actuation / deactuation and the maximum value to reach before fully actuating the crank are all configurable.
Data Arrays¶
vectordata[0].x: The rate at whichactioncooldownincrements per update cycle when the crank is actuatedvectordata[0].y: The rate at whichactioncooldowndecrements per update cycle when the crank is not actuatedvectordata[0].z: The maximum value ofactioncooldownallowed where the crank is considered fully actuated when reachedvectordata[1]: The base angle vector to rotate the crank every update cycles that it is actuated
Additional data¶
activationflag: If above 0, a flag slot that if was already true on SetUp, the crank will start with itshitset to true
Setup¶
- entity.
rigidgets effectively fixed by placing it in kinematic mode without gravity and all constraints frozen - entity.
alwaysactiveis set to true nointeractis set to true- if the
activationflagflags slot is true,hitis also set to true. - From there some adjustements happens based on the
originalid's AnimID(nothing happens if it doesn't match any of them):SwitchCrystalandBigCrystalSwitch: A GlowTrigger is added to the entity.model's first child with itsparentset to this object and theglowpartsset to a single element corresponding to the MeshRender already attached to the first entity.modelchild.WoodenSwitchandSteelSwitch:internaldatais initialised to a single element being -60 if it's aWoodenSwitchor -100 if it's aSteelSwitch, Then, themoveobjis set to the entity.modelfirst child and ifhitwas set to true earlier, its angles are set to (0.0,internaldata[0], 0.0)
- If the player is present, all collision between the
boxcoland the player's wall detector are ignored. - If the
originalidis not amongBigCrystalSwitch,WoodenSwitchorSteelSwitch, AddPushder is called.
Update¶
Updates are disabled if the player doesn't exist.
hit is set to true if the player.beemerang is present and the distance between it and this object is less than 1.75. Otherwise, it is set to false.
If hit is true then actioncooldown is incremented by the game's frametime * vectordata[0].x, but only if the actioncooldown is less than vectordata[0].z (meaning the crank isn't fully actuated) otherwise, nothing happens.
If hit is false and the actioncooldown is above 0.0, it is decremented by the game's frametime * vectordata[0].y
From there, the ratio of the switch actuation is calculated by multiplying the game's frametime with (actioncooldown / vectordata[0].z) which is then clamped from 0.0 to 1.0. (0.0 being no actuation and 1.0 being fully actuated).
The entity.model angles are set to the actuation ratio * vectordata[1] which rotates it proportionally to the crank actuation.
If the ratio is 0 or lower, the entity.sound is set to stop looping. Otherwise, PlaySound is called with the SpinSwitch0 clip at half volume if the entity.sound wasn't playing already. It also sets the clip to loop at 0.5 + the actuation ratio as the pitch.
OnTriggerEnter¶
If the other gameObject tag is BeetleHorn, hit is set to true and actioncooldown is incremented by vectordata[0].x * 10.0 then clamped from 0.0 to vectordata[0].z. This slightly actuate the crank the moment Kabbu's Horn Slash collides with it.