playMaker

Author Topic: Instantiating a prefab as a child of another game object[SOLVED]  (Read 5528 times)

MP

  • Playmaker Newbie
  • *
  • Posts: 10
    • View Profile
Instantiating a prefab as a child of another game object[SOLVED]
« on: November 09, 2012, 12:06:25 AM »
I've attempted to use the Create Object Action to instantiate a prefab as a child of another game object, and then use that game object to set the prefab's Spawn Point.

Since the prefab is a weapon, and I'm attaching it to the first person controller, I want it to stick out a bit from the body. I set a position and rotation in addition to the Spawn Point to achieve that.

When I hit play, though, things go awry. The prefab is not in the correct location, and the rotation is off. What am I doing wrong?

Thanks.
« Last Edit: November 12, 2012, 05:58:51 AM by jeanfabre »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14819
  • Official Playmaker Support
    • View Profile
Re: Instantiating a prefab as a child of another game object
« Reply #1 on: November 09, 2012, 12:07:41 AM »
Hi,

 It's likely that you need to manually set the position and rotation to achieve a proper placement. Have you tried that?

bye,

 Jean

MP

  • Playmaker Newbie
  • *
  • Posts: 10
    • View Profile
Re: Instantiating a prefab as a child of another game object
« Reply #2 on: November 09, 2012, 12:36:57 AM »
Well, I used an empty game object as a placeholder for the weapon which would become the prefab. I then set the weapon's local position and rotation to zero, and then moved and rotated the empty game object around so that the weapon was where I wanted it. Then I saved the weapon as a prefab and deleted the weapon from the scene.

When I tried to use the placeholder as the spawn point of the weapon prefab, however, the position and rotation for the instance of the weapon came out all wrong.

So, as far as I can tell, I've tried to set it manually, without success. Did I do something wrong in setting it manually?

Thanks for your help.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14819
  • Official Playmaker Support
    • View Profile
Re: Instantiating a prefab as a child of another game object
« Reply #3 on: November 09, 2012, 03:56:21 AM »
hi,

 It's difficult to say without some screenshots or actually have the fsm to look at it and debug it.

bye,

 Jean

MP

  • Playmaker Newbie
  • *
  • Posts: 10
    • View Profile
Re: Instantiating a prefab as a child of another game object
« Reply #4 on: November 09, 2012, 04:00:13 PM »
Sure, here is a shot of the FSM and the arrow (prefab) it has positioned in outer space.

I have attached an FSM to the "Players_Bow" prefab and used the location of the Players_Bow prefab as the location where I would like the arrow prefab to instantiate. The Players_Bow prefab has already been instantiated in the attached scene, and the state "Fire_Arrow" during which the arrow prefab is instantiated at the Players_Bow location is now active.

Rather than instantiating the arrow at the Players_Bow location in world space, it seems that it has instantiated the arrow very near to what the Players_Bow's local location, taken as a world location, would be, i.e. close to world 0,0,0, way out in outer space.

I don't know how to tell the FSM to instantiate the arrow at the Players_Bow's world space.

Thanks.




Vermz

  • Playmaker Newbie
  • *
  • Posts: 10
    • View Profile
Re: Instantiating a prefab as a child of another game object
« Reply #5 on: November 09, 2012, 05:35:42 PM »
Hey there, just popping in here to see if you are using a different model for your first person weapon or are you trying to use the third person model of the weapon? Or are they the same thing?

MP

  • Playmaker Newbie
  • *
  • Posts: 10
    • View Profile
Re: Instantiating a prefab as a child of another game object
« Reply #6 on: November 09, 2012, 07:46:40 PM »
Sure, thanks. I don't know what you mean by "third person model of the weapon". If you're asking whether I've used the player or the player's weapon as the spawning point for the arrow, then yes, I've done both. Neither seems to work.

MP

  • Playmaker Newbie
  • *
  • Posts: 10
    • View Profile
Re: Instantiating a prefab as a child of another game object
« Reply #7 on: November 10, 2012, 09:26:26 AM »
Well, I think I've diagnosed the problem, and it has nothing to do with playMaker.

I set up a clean project, excluding playMaker. I made two simple scripts (from this YouTube tutorial: ), one which instantiates a missile, and one, on the missile itself, which positions itself and guides itself to a preset target--a simple homing missile.

In the tutorial the instantiation script, attached to the Main Camera, instantiates the missile on the Main Camera, and the homing script, attached to the missile, guides it to the target.

In my version, the instantiation script, attached to the Main Camera, instantiates the missile at 0,0,0 (just like the BowLauncher script had been doing in my game scene), and the homing script, attached to the missile, causes the missile to vibrate back and forth, going nowhere in particular.

I don't know what's wrong yet, but at least I know it isn't playMaker, so I think I'll go on over to the Unity Forum.

I'd mark this question "solved", but I haven't figured out how yet.

Thanks to everyone who has taken a look.
« Last Edit: November 10, 2012, 09:30:26 AM by MP »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14819
  • Official Playmaker Support
    • View Profile
Re: Instantiating a prefab as a child of another game object[SOLVED]
« Reply #8 on: November 12, 2012, 05:59:38 AM »
Hi,

 keep us updated with your findings, I am sure it will benefit others.

bye,

 Jean