Attaches the player to the target game object, keeping the avatar fixed in its current position/rotation relative to the target object (e.g. for use in Vehicles)
Parameter
Type
Description
Space.Scene.PlayerAvatar.AttachTo(targetObject)
--the below scipt makes the player Attach/Detach to/from this object by clicking it--(Example: Seat/Vehicle/Experience etc.. )thisGameObject = Space.Host.ExecutingObjectisAttached =0OnClick=function()if isAttached ==0then Space.Scene.PlayerAvatar.AttachTo(thisGameObject) isAttached =1elseif isAttached ==1then Space.Scene.PlayerAvatar.Detach() isAttached =0endendthisGameObject.AddClickable()thisGameObject.Clickable.Tooltip ="Click to Attach/Detach yourself to/from me"thisGameObject.Clickable.OnClick(OnClick)
Detach
void Detach ()
Detaches the avatar from whatever it may be attached to (only works for the player avatar), including chairs, vehicles and so forth.
Space.Scene.PlayerAvatar.Detach()
--the below scipt makes the player Attach/Detach to/from this object by clicking it--(Example: Seat/Vehicle/Experience etc.. )thisGameObject = Space.Host.ExecutingObjectisAttached =0OnClick=function()if isAttached ==0then Space.Scene.PlayerAvatar.AttachTo(thisGameObject) isAttached =1elseif isAttached ==1then Space.Scene.PlayerAvatar.Detach() isAttached =0endendthisGameObject.AddClickable()thisGameObject.Clickable.Tooltip ="Click to Attach/Detach yourself to/from me"thisGameObject.Clickable.OnClick(OnClick)
OnAvatarAttached
void OnAvatarAttached ()
An event which fires whenever this avatar is attached to a game object in the current scene.
Only works on a white-label deployment due to abuse concerns. Restrictions: The outfit ID needs to be one of the grid template outfits, with all the restrictions that apply to those (i.e. must use either SW content, or content uploaded by a grid admin account).
Parameter
Type
Description
local avatar=Space.Scene.PlayerAvataravatar.LoadOutfit(10001)
--the below script changes the player's outfit into --a pre-defined outfit if they click the object containing the script--(Example: Player clicks on a wardrobe and their outfit changes)--[Only works on white-label deployment]thisGameObject = Space.Host.ExecutingObjectOnClick=function()Space.Scene.PlayerAvatar.LoadOutfit(2662469)endthisGameObject.AddClickable()thisGameObject.Clickable.Tooltip ="Put on your favourite suit"thisGameObject.Clickable.OnClick(OnClick)
ResetOutfit
void ResetOutfit ()
Reset current outfit. (white-label only)
local Space.Scene.PlayerAvatar.ResetOutfit()
--Clicking this object will reset player avatar's outfitthisObject = Space.Host.ExecutingObjectthisPlayer = Space.Scene.PlayerAvatarOnClick=function()thisPlayer.ResetOutfit() endthisObject.AddClickable()thisObject.Clickable.OnClick(OnClick)
local avatar=Space.Scene.PlayerAvataravatar.Register("MyName","MyPassword","MyEmail",false,function () Space.Log("Success!")end,function () Space.Log("OnError!!")end)
ResetOutfitToTemplate
void ResetOutfitToTemplate (int outfitID)
Reset current outfit to a specific template. (white-label only)
Parameter
Type
Description
local avatar=Space.Scene.PlayerAvataravatar.ResetOutfitToTemplate(10001)
--Clicking this object will reset player avatar's outfit to a specific template.thisObject = Space.Host.ExecutingObjectthisPlayer = Space.Scene.PlayerAvatarOnClick=function()thisPlayer.ResetOutfitToTemplate(10001)endthisObject.AddClickable()thisObject.Clickable.OnClick(OnClick)
-- Best used with non humanoid modelslocal bone = Space.Scene.PlayerAvatar.FindBone("Hips/Spine/Chest/LeftShoulder"); -- Gets the bone by pathSpace.Log(bone.Name); -- Prints the retrieved bones name, which will match the last name in the path specified.or-- Best used with humanoid modelslocal bone = Space.Scene.PlayerAvatar.FindBone("LeftShoulder"); -- Gets bone by UnityEngine.HumanTrait.BoneName[]Space.Log(bone.Name); -- Prints the bone name of the corresponding search parameter, which when using a default avatar, it will print "LeftShoulder"--[[UnityEngine.HumanTrait.BoneName[]Body: Hips, Spine, Chest, UpperChestHead: Neck, Jaw, Head, LeftEye, RightEyeLeft Arm: LeftShoulder, LeftUpperArm, LeftLowerArm, LeftHandLeft Leg: LeftUpperLeg, LeftLowerLeg, LeftFoot, LeftToesRight Arm: RightShoulder, RightUpperArm, RightLowerArm, RightHandRight Leg: RightUpperLeg, RightLowerLeg, RightFoot, RightToesLeft Hand (Thumb): LeftThumbProximal, LeftThumbIntermediate, LeftThumbDistalLeft Hand (Index): LeftIndexProximal, LeftIndexIntermediate, LeftIndexDistalLeft Hand (Middle): LeftMiddleProximal, LeftMiddleIntermediate, LeftMiddleDistalLeft Hand (Ring): LeftRingProximal, LeftRingIntermediate, LeftRingDistalLeft Hand (Little): LeftLittleProximal, LeftLittleIntermediate, LeftLittleDistalRight Hand (Thumb): RightThumbProximal, RightThumbIntermediate, RightThumbDistalRight Hand (Index): RightIndexProximal, RightIndexIntermediate, RightIndexDistalRight Hand (Middle): RightMiddleProximal, RightMiddleIntermediate, RightMiddleDistalRight Hand (Ring): RightRingProximal, RightRingIntermediate, RightRingDistalRight Hand (Little): RightLittleProximal, RightLittleIntermediate, RightLittleDistal]]
--this script will set your avatar's "right hand" as parent of this object--this way this object will be a child of your right hand and therefore move with it--(Example: clicking on a gun to equip it)thisGameObject = Space.Host.ExecutingObjectOnClick=function()RightHand = Space.Scene.PlayerAvatar.FindBone("RightHand")thisGameObject.SetParent(RightHand)thisGameObject.LocalPosition = Vector.New(0,0,0) -- resetting position to match handendthisGameObject.AddClickable()thisGameObject.Clickable.Tooltip="Click to Equip "thisGameObject.Clickable.OnClick(OnClick)
--the below script teleports player to a specific landmark--if they click the object containing it--(Example: A region promotional/advertisement sign)--[You need a landmark in the scene with name "Fashion Section Landmark"thisGameObject = Space.Host.ExecutingObjectOnClick=function()Space.Scene.PlayerAvatar.Teleport("Fashion Section Landmark")endthisGameObject.AddClickable()thisGameObject.Clickable.Tooltip ="Click me to go to the fashion section!"thisGameObject.Clickable.OnClick(OnClick)
--the below scipt makes the player Play/Stop a custom animation when clicking this object--(Example: Dance Machine )--[Required: Place an animation in the first "Resource" in the scripting runtime]thisGameObject = Space.Host.ExecutingObjectisDancing =0OnClick=function()if isDancing ==0then Space.Scene.PlayerAvatar.StartCustomAnimation(Space.Resources[1]) isDancing =1elseif isDancing ==1then Space.Scene.PlayerAvatar.StopCustomAnimation() isDancing =0endendthisGameObject.AddClickable()thisGameObject.Clickable.Tooltip ="Click to Start/Stop dancing"thisGameObject.Clickable.OnClick(OnClick)
--the below scipt makes the player Play/Stop a custom animation when clicking this object--(Example: Dance Machine )--[Required: Place an animation in the first "Resource" in the scripting runtime]thisGameObject = Space.Host.ExecutingObjectisDancing =0OnClick=function()if isDancing ==0then Space.Scene.PlayerAvatar.StartCustomAnimation(Space.Resources[1]) isDancing =1elseif isDancing ==1then Space.Scene.PlayerAvatar.StopCustomAnimation() isDancing =0endendthisGameObject.AddClickable()thisGameObject.Clickable.Tooltip ="Click to Start/Stop dancing"thisGameObject.Clickable.OnClick(OnClick)
OnAvatarReload
void OnAvatarReload (Closure o)
This event will be called when the avatar gets loaded.
Parameter
Type
Description
o
Closure (callback)
A function that will be called once the OnAvatarReload event is triggered.
local avatar=Space.Scene.PlayerAvataravatar.OnAvatarReload(function () Space.Log(avatar.OutfitID)end)
--this script ensures the avatar is still animating after their avatar gets reloadedthisPlayer = Space.Scene.PlayerAvatartheAnimation = Space.GetResource("The Animation") --add animation to resources in Scripting RuntimewasAnimated =true--you'll need to set this according to the situation, its true now for example's sakeResetDance=function()if wasAnimated then thisPlayer.PlayCustomAnimation(theAnimation)endendthisPlayer.OnAvatarReload(ResetDance)
SynchroniseState
void SynchroniseState ()
Synchronise avatar's state to network.
Space.Scene.PlayerAvatar.SynchroniseState()
StartFly
void StartFly ()
Puts the avatar into Fly Mode.
Space.Scene.PlayerAvatar.StartFly()
--the below script teleports the player to a sky location after he clicks--but then immediately puts the character in fly mode so they don't fall back down--(Example: Sky exhibit)thisGameObject = Space.Host.ExecutingObjectOnClick=function()Space.Scene.PlayerAvatar.Teleport(Vector.New(0,10,0))Space.Scene.PlayerAvatar.StartFly()endthisGameObject.AddClickable()thisGameObject.Clickable.Tooltip ="Click me to view our sky exhibit!"thisGameObject.Clickable.OnClick(OnClick)
EndFly
void EndFly ()
Takes the avatar out of Fly Mode.
Space.Scene.PlayerAvatar.EndFly()
--the below script a player flying in the sky back to the ground --but then immediately end's the character fly mode so they are standing--(Example: Going back down to ground from Sky exhibit)thisGameObject = Space.Host.ExecutingObjectOnClick=function()Space.Scene.PlayerAvatar.Teleport(Vector.New(0,0,0))Space.Scene.PlayerAvatar.EndFly()endthisGameObject.AddClickable()thisGameObject.Clickable.Tooltip ="Click me to go back to the ground!"thisGameObject.Clickable.OnClick(OnClick)
OnAvatarSkeletonReload
void OnAvatarSkeletonReload (Closure o)
This event will be called when the avatar skeleton gets loaded.
Parameter
Type
Description
o
Closure (callback)
A function that will be called once the OnAvatarSkeletonReload event is trigged.
--this script ensures the avatar is still animating after their avatar's skeleton gets reloadedthisPlayer = Space.Scene.PlayerAvatartheAnimation = Space.GetResource("The Animation") --add animation to resources in Scripting RuntimewasAnimated =true--you'll need to set this according to the situation, its true now for example's sakeResetDance=function()if wasAnimated then thisPlayer.PlayCustomAnimation(theAnimation)endendthisPlayer.OnAvatarSkeletonReload(ResetDance)
--this script, once clicked, will get all avatars in the scene--and print their Username(including self)--(Example: scoreboards/radars/scanners/game machines)thisGameObject = Space.Host.ExecutingObjectOnClick=function()allAvatars = Space.Scene.AllAvatarsfor var=1, #allAvatars dolocal Username = allAvatars[var].Username Space.Log("Username: " .. Username)endendthisGameObject.AddClickable() thisGameObject.Clickable.Tooltip ="Click to print all avatars' Username"thisGameObject.Clickable.OnClick(OnClick)
--this script, once clicked, will get all avatars in the scene--and print their Title and Username(including self)thisGameObject = Space.Host.ExecutingObjectOnClick=function()allAvatars = Space.Scene.AllAvatarsfor var=1, #allAvatars dolocal Username = allAvatars[var].Usernamelocal Title = allAvatars[var].Title Space.Log(Title .." " .. Username)endendthisGameObject.AddClickable() thisGameObject.Clickable.Tooltip ="Click to print all avatars' Titles and Username"thisGameObject.Clickable.OnClick(OnClick)
Returns the avatar's user ID, please note if you store these, this is a 'long' value not a 'int'.
playerID = Space.Scene.PlayerAvatar.ID
--this script, once clicked, will get all avatars in the scene--and print their ID(including self)--(Example: scoreboards/radars/scanners/game machines)thisGameObject = Space.Host.ExecutingObjectOnClick=function()allAvatars = Space.Scene.AllAvatarsfor var=1, #allAvatars dolocal ID = allAvatars[var].ID Space.Log("ID: " .. ID)endendthisGameObject.AddClickable() thisGameObject.Clickable.Tooltip ="Click to print all avatars' ID"thisGameObject.Clickable.OnClick(OnClick)
IsAttached
bool IsAttachedget
Returns True if avatar is Attached
isAttached = Space.Scene.PlayerAvatar.isAttached
MovementSpeed
float MovementSpeedgetset
How fast the avatar's movement is
Space.Scene.PlayerAvatar =20
--the below scipt makes the object give the player triple movement speed--once it's clicked, and then returns them to original speed after 10 seconds--(Example: Triple Speed Powerup (vatar running race))thisGameObject = Space.Host.ExecutingObjectTripleSpeedCoroutine=function()local originalSpeed = Space.Scene.PlayerAvatar.MovementSpeedSpace.Scene.PlayerAvatar.MovementSpeed = originalSpeed *3coroutine.yield(10)Space.Scene.PlayerAvatar.MovementSpeed = originalSpeedendOnClick=function()Space.Host.StartCoroutine(TripleSpeedCoroutine)endthisGameObject.AddClickable()thisGameObject.Clickable.Tooltip ="Triple Speed Powerup!"thisGameObject.Clickable.OnClick(OnClick)
JumpHeight
float JumpHeightgetset
How high the avatar's jump is
Space.Scene.PlayerAvatar.JumpHeight =20
--the below scipt makes the object give the player triple jump height--once it's clicked, and then returns them to original jump height after 10 seconds--(Example: Triple Jump Height Powerup )thisGameObject = Space.Host.ExecutingObjectoriginalJumpHeight = Space.Scene.PlayerAvatar.JumpHeightTripleJumpHeightCoroutine=function()Space.Scene.PlayerAvatar.JumpHeight = originalJumpHeight *3coroutine.yield(10)Space.Scene.PlayerAvatar.JumpHeight = originalJumpHeightendOnClick=function()Space.Host.StartCoroutine(TripleJumpHeightCoroutine)endthisGameObject.AddClickable()thisGameObject.Clickable.Tooltip ="Triple JumpHeight Powerup!"thisGameObject.Clickable.OnClick(OnClick)
Guest
bool Guestget
Is this Avatar a Guest?
isGuest = Space.Scene.PlayerAvatar.Guest
--this script will make this object non-clickable for guest playersthisObject = Space.Host.ExecutingObjectthisPlayer = Space.Scene.PlayerAvatarOnClick=function()Space.Log("Do Something")endifnot thisPlayer.Guest then--if player is not guestthisObject.AddClickable()thisObject.Clickable.OnClick(OnClick)end
OutfitID
long OutfitIDget
Returns the current outfit ID of the avatar
avOutfit = Space.Scene.PlayerAvatar.OutfitID
Loaded
bool Loadedget
Returns true if avatar is Loaded
isLoaded = Space.Scene.PlayerAvatar.Loaded
--this script will wait for a joining avatar to load first before making it play an animation--(otherwise that animation may be reset if played before load is complete)NewJoinAnimation = Space.GetResource("The Animation")OnPlayerJoin=function(NewAvatar) Space.Host.StartCoroutine(function()whilenot NewAvatar.Loaded docoroutine.yield(0) end--makes it wait Space.Log("yes") NewAvatar.PlayCustomAnimation(NewJoinAnimation) --at this point Loaded is Trueend)endSpace.Scene.OnPlayerJoin(OnPlayerJoin)
Returns a reference to avatar's skeleton GameObject
avSkeleton = Space.Scene.PlayerAvatar.Skeleton
--clicking this object will replace your avatar's animator controller (found on the skeleton)thisObject = Space.Host.ExecutingObjectthisPlayer = Space.Scene.PlayerAvatarcustomController = Space.GetResource("animcont")OnClick=function() thisPlayer.Skeleton.Animator.Controller = customControllerendthisObject.AddClickable()thisObject.Clickable.OnClick(OnClick)
BlockMovement
bool BlockMovementgetset
If set to True, avatar's movement will be blocked
Space.Scene.PlayerAvatar.BlockMovement =true
--the below scipt makes this object a boundary area where any user entering it--will be blocked from movement for 10 seconds, then the object will release controls and--destry itself after that--(Example: freezing trap)--[This object's collider needs to be set as IsTrigger (Please read about OnTriggerStart for troubleshooting)]thisGameObject = Space.Host.ExecutingObjectFrozenTime =0.0OnTriggerStart=function(TriggerStarter)if TriggerStarter.Root.Avatar ~=nilthenif TriggerStarter.Root.Avatar.Username == Space.Scene.PlayerAvatar.Username then Space.Scene.PlayerAvatar.BlockMovement =trueendendendOnTriggerStay=function(TriggerStayer)if TriggerStayer.Root.Avatar ~=nilthenif TriggerStayer.Root.Avatar.Username == Space.Scene.PlayerAvatar.Username then FrozenTime = FrozenTime + Space.DeltaTimeif FrozenTime >20then Space.Scene.PlayerAvatar.BlockMovement =false thisGameObject.Destroy()endendendendthisGameObject.SubscribeToEvents()thisGameObject.OnTriggerStart(OnTriggerStart)thisGameObject.OnTriggerStay(OnTriggerStay)
BlockRun
bool BlockRungetset
Is the Avatar blocked from running?
avatar=Space.Scene.PlayerAvatar.BlockRun =true
--this script will block a player's run ability when entering trigger collider and release it when leaving--[Requires this object to have a "Trigger" collider]thisObject = Space.Host.ExecutingObjectthisPlayer = Space.Scene.PlayerAvatarOTS=function(gameObject)if gameObject.Avatar ~=niland thisPlayer == gameObject.Avatar then thisPlayer.BlockRun =trueendendOTE=function(gameObject)if gameObject.Avatar ~=niland thisPlayer == gameObject.Avatar then thisPlayer.BlockRun =falseendendthisObject.OnTriggerStart(OTS)thisObject.OnTriggerExit(OTE)
BlockFly
bool BlockFlygetset
Is the Avatar blocked from flying?
Space.Scene.PlayerAvatar.BlockFly =true
--this script will block a player's fly ability when entering trigger collider and release it when leaving--[Requires this object to have a "Trigger" collider]thisObject = Space.Host.ExecutingObjectthisPlayer = Space.Scene.PlayerAvatarOTS=function(gameObject)if gameObject.Avatar ~=niland thisPlayer == gameObject.Avatar then thisPlayer.BlockFly =trueendendOTE=function(gameObject)if gameObject.Avatar ~=niland thisPlayer == gameObject.Avatar then thisPlayer.BlockFly =falseendendthisObject.OnTriggerStart(OTS)thisObject.OnTriggerExit(OTE)
BlockCrouch
bool BlockCrouchgetset
Is the Avatar blocked from crouching?
Space.Scene.PlayerAvatar.BlockCrouch =true
--this script will block a player's crouch ability when entering trigger collider and release it when leaving--[Requires this object to have a "Trigger" collider]thisObject = Space.Host.ExecutingObjectthisPlayer = Space.Scene.PlayerAvatarOTS=function(gameObject)if gameObject.Avatar ~=niland thisPlayer == gameObject.Avatar then thisPlayer.BlockCrouch =trueendendOTE=function(gameObject)if gameObject.Avatar ~=niland thisPlayer == gameObject.Avatar then thisPlayer.BlockCrouch =falseendendthisObject.OnTriggerStart(OTS)thisObject.OnTriggerExit(OTE)
BlockJump
bool BlockJumpgetset
Is the Avatar blocked from jumping?
Space.Scene.PlayerAvatar.BlockJump =true
--this script will block a player's jump ability when entering trigger collider and release it when leaving--[Requires this object to have a "Trigger" collider]thisObject = Space.Host.ExecutingObjectthisPlayer = Space.Scene.PlayerAvatarOTS=function(gameObject)if gameObject.Avatar ~=niland thisPlayer == gameObject.Avatar then thisPlayer.BlockJump=trueendendOTE=function(gameObject)if gameObject.Avatar ~=niland thisPlayer == gameObject.Avatar then thisPlayer.BlockJump=falseendendthisObject.OnTriggerStart(OTS)thisObject.OnTriggerExit(OTE)
--Clicking this object will teleport you 2 units forward and make you face the opposite waythisObject = Space.Host.ExecutingObjectthisPlayer = Space.Scene.PlayerAvatarOnClick=function()local targetPos = thisPlayer.GameObject.WorldPosition + (thisPlayer.GameObject.Forward *2) local targetRot = thisPlayer.GameObject.WorldRotation * Quaternion.AngleAxis(Vector.Up, 180)thisPlayer.Teleport(targetPos, targetRot)endthisObject.AddClickable()thisObject.Clickable.OnClick(OnClick)