Search Unity

Putting objects inside of player model while in game?

Discussion in 'Scripting' started by theBundyXVO, Sep 18, 2014.

  1. theBundyXVO

    theBundyXVO

    Joined:
    Sep 15, 2014
    Posts:
    24
    Hello,
    I'm trying to figure out a way to spawn objects inside of a player's model while the game is running and I can't seem to figure out how to do it. I would think I'd have to grab the player coordinates, then find the width of the player model, then divide it in half to find the center of the model then spawn the object? And if thats the correct way to do it, how would I go about doing such a thing? Also, these models are being dynamically loaded (meaning I'm loading them from URLs and placing them in the game as its running) so I don't have any set information on the models. I'm pretty stuck for ideas.
    Any help would be loved, thanks everyone.
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    It's not as hard as all that. The player's position is just transform.position. Spawn your new object there, and it will be at the same coordinates as the player. Or, if you want it at some small position relative to the player's position — taking into account the current position and rotation of the player — then use transform.TransformScale(localPos).

    Now I'd like to ask you a question... how are you loading these models from a URL? I didn't think Unity had any standard way to do that.
     
    theBundyXVO likes this.
  3. theBundyXVO

    theBundyXVO

    Joined:
    Sep 15, 2014
    Posts:
    24
    Thanks man, you solved it. & I just found some resources around the web on it, it pretty much just downloads as the game goes and calls on them.
     
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Can you share a link? I'm going to need something like this soon. I found this OBJ reader, but if you found something better, I'd love to learn about it.

    (Glad you got the spawn position stuff all sorted out, BTW.)
     
  5. theBundyXVO

    theBundyXVO

    Joined:
    Sep 15, 2014
    Posts:
    24