1. The space forums use a separate registration system from the main virtual world. To comment on these forums, you need to create a separate forum account.
    Dismiss Notice
  2. Hey there, if you want some direct help without hopping inworld - try our Discord channel at https://discord.gg/mptfycQ
    Dismiss Notice

Click to Wear - Attach object to Avatar on Mouse Click

Discussion in 'Job Offers' started by Juliein3D, Apr 3, 2017.

Share This Page

  1. Juliein3D

    By:Juliein3DApr 3, 2017
    New Member

    Joined:
    Apr 3, 2017
    Messages:
    18
    Likes Received:
    6
    Can pay $100 via for this capability and am OK to share with all.

    Would like a script for use in Space that enables me to click to wear something on an avatar.
    First use, is click to put on a pair of goggles but will need other uses such as click to put a paper under the avatar's arm, etc.

    The avatars I use are often full suits, so needs to work for both those dressed via the Space avatar modified avatars as well as the ones I bring in that are full avatars from tools such as Fuse.

    As the creator I need a way to defined the wearable object, the wear trigger object (a user mouse clicks to wear that object), the unwear trigger object (object the user mouse clicks to take off the object) and a capability for defining the placement on the object when warn and where to put it when taken off.

    For the end user I need them to be able to mouse click (or touch some day ;-) the wear trigger object to put on the object and the unwear object to take off the object.

    End users will need to be able to wear more than one wearable item.

    Summary - critical first features:
    1. Creator ability to identify an object 1-n objects as wearable
    2. Creator ability to place the object where it should attach when warn
    3. Creator ability to as the target click to wear object and click to unwear objects (need not be the object itself)
    4. End users ability to mouse click the wear and unwear objects to wear and unwear the object in the predefined location of attachment
    5. work for externally created avatars with full suits from Fuse as well as with Spaces provided clothed avatars

    Adam suggested the proper pseudocode for the basics on this within the Skype as a basis of this. The ideas from Adam with comments from James were:

    Adam F (swc): basically attachments are just things attached to the avatar skeleton, so you could use the Scene.Find("Player Avatar/capsule/reference/spine/spine1/neck/head"); or whatever. Then attach the item as a child of it

    James Stallings: yeah but how do you then attach it ...ahh parenting
    James Stallings: is there a way to adjust it's orientation?

    Adam F (swc): Local rotation & position
    Adam F (swc):The only thing you need to watch for - you need to search twice.
    Once for the male avatar, check if the gameobject is nil, then again for the female, or vice versa. Since the avatar skeleton is sliiiightly different between the two (the root node is named differently)

    Needed working by 15 April if possible! Like to learn to script for Spaces but need this sooner than I can get a handle on scripting! ;-)
     
    Last edited: Apr 3, 2017
    Mike (CNDG) likes this.
  2. Juliein3D

    By:Juliein3DApr 3, 2017
    New Member

    Joined:
    Apr 3, 2017
    Messages:
    18
    Likes Received:
    6
    thanks! will pay and will share with all! Seems like a very useful, reusable capability!
     
  3. Trilo

    By:TriloApr 4, 2017
    Active Member

    Joined:
    Dec 6, 2016
    Messages:
    317
    Likes Received:
    46
    It sounds like you're looking for something that would bypass (or work on top of) the way the current Space wardrobe system works? I'm not a scripter but would be curious to see the kinds of alternative clothing/dressing systems are possible.
     
  4. James Stallings

    By:James StallingsApr 13, 2017
    Member

    Joined:
    Sep 28, 2016
    Messages:
    69
    Likes Received:
    18

    'zactly what I was thinking :)
     
  5. Adam

    By:AdamApr 18, 2017
    Developer
    Staff Member Moderator

    Joined:
    Aug 21, 2014
    Messages:
    695
    Likes Received:
    137
    OK - here's the basic script you want.

    Code:
    local this = Space.Host.ExecutingObject;
    local boneA = "Player Avatar/capsule/Female(Clone)/Reference/Hips/Spine/Chest/RightShoulder/RightArm/RightForeArm/RightHand";
    local boneB = "Player Avatar/capsule/Male(Clone)/Reference/Hips/Spine/Chest/RightShoulder/RightArm/RightForeArm/RightHand";
    
    local playerBone = Space.Scene.Find(boneA);
    if (playerBone == nil or not playerBone.Exists) then
        playerBone = Space.Scene.Find(boneB);
    end
    
    this.Parent = playerBone
    this.LocalPosition = Vector.New(0,0,0)
    this.LocalRotation = Quaternion.Euler(0,0,0)
    this.LocalScale = Vector.New(1,1,1)
    
    Disable it by default - then activate it on demand using whatever method you like (e.g. the clickable could call SetActive).

    For the head, replace:

    Code:
    local boneA = "Player Avatar/capsule/Female(Clone)/Reference/Hips/Spine/Chest/RightShoulder/RightArm/RightForeArm/RightHand";
    local boneB = "Player Avatar/capsule/Male(Clone)/Reference/Hips/Spine/Chest/RightShoulder/RightArm/RightForeArm/RightHand";
    
    with:

    Code:
    local boneA = "Player Avatar/capsule/Female(Clone)/Reference/Hips/Spine/Chest/Neck/Head";
    local boneB = "Player Avatar/capsule/Male(Clone)/Reference/Hips/Spine/Chest/Neck/Head";
    
    This is a little hacky since it requires looking up the universal 'Player Avatar' - which while present in the scene, may not always in future have the same name. (Technically it's a internal component you're reaching into). It'll also break when using custom skeletons. (i.e. only works with the space default avs, unless you're rigged to our same bone setup)

    To make this more long lived, I've also added two new functions to the scripting API - SGameObject.FindInChildren, and SAvatar.FindBone - those will be in the next release.

    To use those, it's much simpler.

    First - find the name of the bone you want in the list here; and second - replace the script with this one.

    Code:
    this.Parent = Space.Scene.PlayerAvatar.FindBone("RightHand")
    this.LocalPosition = Vector.New(0,0,0)
    this.LocalRotation = Quaternion.Euler(0,0,0)
    this.LocalScale = Vector.New(1,1,1)
    
     
    AshaSekayi likes this.
  6. James Stallings

    By:James StallingsApr 18, 2017
    Member

    Joined:
    Sep 28, 2016
    Messages:
    69
    Likes Received:
    18
    Sweet. Worth a hundred times the bounty :)
     
  7. Juliein3D

    By:Juliein3DApr 18, 2017
    New Member

    Joined:
    Apr 3, 2017
    Messages:
    18
    Likes Received:
    6
    thanks you Adam, you know I needed this, thank you James for considering the work too!! Now to use it, yeeha!
     
  8. Juliein3D

    By:Juliein3DApr 27, 2017
    New Member

    Joined:
    Apr 3, 2017
    Messages:
    18
    Likes Received:
    6
    Reminder to anyone using this that to test it in the editor you need to substitute PlayerChar for Player Avatar so you can see it in the editor, but don't forget to change it back to use it! And not sure its working in curator or live so far. Might need to wait for the updated APIs, but i've got it working in the Editor, thanks to this and Rohan's help!!
     
    Last edited: Apr 27, 2017
    AshaSekayi likes this.
  9. Juliein3D

    By:Juliein3DMay 12, 2017
    New Member

    Joined:
    Apr 3, 2017
    Messages:
    18
    Likes Received:
    6
    Adam adjusted the code above for use with the 5.6 update this week. He added the first line and then it worked! Like magic!

    local this = Space.Host.ExecutingObject;
    this.Parent = Space.Scene.PlayerAvatar.FindBone("RightHand")
    this.LocalPosition = Vector.New(0,0,0)
    this.LocalRotation = Quaternion.Euler(0,0,0)
    this.LocalScale = Vector.New(1,1,1)
     

    Attached Files:

    AshaSekayi likes this.