Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Swapping y and z-axis in an imported model

Discussion in 'Scripting' started by mich13lfifa, Aug 29, 2020.

  1. mich13lfifa

    mich13lfifa

    Joined:
    Aug 26, 2020
    Posts:
    2
    Hi, I have an imported model of a bullet, which is pointing downwards instead of forwards. Logically you would apply a (0, 0, 270) vector3 to point it forwards, however any way I try this ruins the program in some way and does not actually fix the issue. It arises because I assume the modelling software used for this swaps the y and z axis. How can I fix this?

    I posted in scripting because I use a prefab which is instantiated in script, so I assume a solution in script is best.
     
  2. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,587
    If you really want to swap the axis of the vertices making up the mesh, then you'll have to create a script to go through the mesh vertices, swap the values for y and z axis and save the newly created mesh as a new asset.

    However, i imagine the problem is just that you are changing the rotation of the instantiated object, which is used in some way or another by the script, thus messing up its functionality. So instead of changing the orientation of the parent object itself, create a child object inside the prefab which you attach the bullet mesh to. You can then freely rotate this child 'inside the parent' to your desired orientation, without any effect on the parent rotation.
     
    mich13lfifa likes this.
  3. WarmedxMints

    WarmedxMints

    Joined:
    Feb 6, 2017
    Posts:
    1,035
    Personally I would load the model into blender, rotate it, and export it as fbx and you can set the forward axis. Another option is to put the model on a child gameobject and rotate it locally how you wish and then rotate/move the parent in game.
     
  4. mich13lfifa

    mich13lfifa

    Joined:
    Aug 26, 2020
    Posts:
    2
    Thank you so much, this actually worked! I was stuck on this for hours
     
  5. aJames4423

    aJames4423

    Joined:
    Jul 23, 2022
    Posts:
    2