playMaker

Author Topic: Spawnable player object's Origin causing some problems. [SOLVED]  (Read 2527 times)

TonanBora

  • Playmaker Newbie
  • *
  • Posts: 11
Spawnable player object's Origin causing some problems. [SOLVED]
« on: February 02, 2014, 02:27:09 PM »
First off, let me explain the lay out.
When I first created my game, I placed and made a player cube object.
I then created a prefab of this object and deleted the one in the scene (because it does not start off in the scene).
latter, as I was creating object AI, I tried to create a "Rally" command button, that when pressed, would send a rally event to all cubes of the same color.
The rally event is supposed to have all the cubes of the same color as the player cube move toward the player cube. 
As I mentioned, I turned my player cube into a prefab after placing it in the scene, then deleting the one in the scene. 
The rally command kind of worked, except that the cubes rallied around the original player cube's origin, not the player cube that spawned in (the prefab).

I opened the prefab player cube in inspector and checked its transform, which was indeed at the position the cubes kept going to.

I tried setting the transform to (0,0,0) but then the cubes would rally to (0,0,0) and not the prefab player cube that was spawned in.

My question is how to get the origin to set, and move with, the prefab player cube so that the other cubes will properly rally around the player cube.
« Last Edit: February 03, 2014, 11:10:24 PM by TonanBora »

Breadman

  • Full Member
  • ***
  • Posts: 185
  • Derp
Re: Spawnable player object's Origin causing some problems.
« Reply #1 on: February 03, 2014, 01:41:44 AM »
If I understand correctly, you want gameobjects to move towards the player's position when a key is pressed, correct?

I'm not sure exactly how your FSM handles this, but it is working in that it sends the objects to what was once the players position.

Between the state that reads the "rally" key press/mouse click, and the state that actually moves the objects to the player's position, add a new state that gets the player's position [get position action], and store it in some variable (let's say "playerposition"). Once this is finished, pass the FSM to the state that handles the objects actually moving, and set their location to the "playerposition" variable.


TonanBora

  • Playmaker Newbie
  • *
  • Posts: 11
Re: Spawnable player object's Origin causing some problems.
« Reply #2 on: February 03, 2014, 11:01:51 AM »
I have tried that as well, but it keeps getting the position of the prefab transform and not the transform of the spawned player object.

Here is how the rally command I set up works:
At the start of the game, you pick your team (red or blue).  Depending on which team you select, the game sets up itself and spawns in the player object at your teams spawn point, it then sets a global GameObject variable named
"<team picked> Commander"(for example, if you picked red team, it would set the variable Red Commander) as the Player Object. 
Once the Rally command is given, it is sent to all team members.  Each team member then finds the position of their team's Commander variable and stores it in a Vector 3 variable called "Commander Location" then, in the same state, it moves toward the "Commander Location" variable.   

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Spawnable player object's Origin causing some problems.
« Reply #3 on: February 03, 2014, 11:06:17 AM »
Is the player commander object in a wrapper?
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

TonanBora

  • Playmaker Newbie
  • *
  • Posts: 11
Re: Spawnable player object's Origin causing some problems.
« Reply #4 on: February 03, 2014, 11:08:38 PM »
Not sure what a wrapper is, but I found a solution!  ::)
I feel kind of stupid not thinking of this earlier.  :-[ 
As I mentioned above, the rallying team mates where getting the location of the PREFAB, not the actual spawned Player Object.  So I went and created a new tag for the player, had the game find the closest object with said tag AFTER the player is spawned in and store that object as the Commander of the chosen team.  I then tested the game and the player's team rallied around him.
Duh ???..... lol