playMaker

Author Topic: Mirror Game Object  (Read 2219 times)

Nog

  • Playmaker Newbie
  • *
  • Posts: 47
Mirror Game Object
« on: October 22, 2015, 06:42:13 PM »
Hello,

I have a game object that is a child to a parent game object. I then have the parent centered in the middle of my character, and this object is a child to another parent that is also centered in the middle of my character. The main parent game object follows my character around in the world through the Itween Move Update action.

 I would like to mirror the child game object directly to the opposite side of the character when I push a button. I have tried using the get and set rotation actions. I get the rotation vector of the main parent object, invert the vector of the parent's rotation, and use the inverted parent rotation to set the rotation of the next parent the child is connected to. This works perfectly as long as the forward axis is X; however, if the character moves to another location, the forward axis seems to change in the world to the Z axis, and the mirroring effect is a mess (instead of mirroring, the child flips over itself.

Is there a way a way to get a game object to mirror itself? I hope my description makes sense.

ManicMinerUK

  • Junior Playmaker
  • **
  • Posts: 51
Re: Mirror Game Object
« Reply #1 on: October 22, 2015, 09:20:24 PM »
I'm not sure I fully understand your description, but if it's what I *think* you are looking for, you could just get the position co-ords of the object you want to mirror, multiply each of them by -1, and then set the position co-ords to those new values?

Nog

  • Playmaker Newbie
  • *
  • Posts: 47
Re: Mirror Game Object
« Reply #2 on: October 22, 2015, 09:51:30 PM »
Hello ManicMinerUK,

Thank you for the help. I believe that is what I have been doing, but I have been getting the rotation of the parent instead of the position, and inverting or multiplying the rotation vector by -1. It rotates or flips it to the opposite side. This mirrors everything over perfectly, but when I move around the world, the mirroring becomes a mess. I believe it is because world coordinates change according to where the player is in 3d space. For example, there are times when the forward axis is Z, there are times when the forward axis is X, and sometimes it is both. I could be wrong, but it seems to be a world space issue. Maybe mirroring a game object is not possible? I will give your suggestion a try and see what happens.

Again, thanks for the help.

ManicMinerUK

  • Junior Playmaker
  • **
  • Posts: 51
Re: Mirror Game Object
« Reply #3 on: October 23, 2015, 09:56:27 PM »
My guess would be you encountering some of the classic problems with Unity rotations... As you can imagine, a rotation of 90 in an axis is also a rotation of -270, and Unity will fairly happily just flip between these two values, pretty much on it's own whims, as far as I can tell. For this reason doing maths with euler rotations in Unity is probably to be avoided...

I would definitely look to stick to a solution that used position co-ordinates rather than rotations.