Search Unity

Rocking Movement For Whole Level Interior Causes Parts To Move Independently

Discussion in 'Animation' started by apventures, Apr 11, 2019.

  1. apventures

    apventures

    Joined:
    Aug 6, 2018
    Posts:
    24
    Hello everyone. This is a newbie issue I'm having where I have a floorplan and inside of the floorplan GameObject are several components that make up fan vents, walls, floors, windows, etc.

    I've created an Animation clip for rocking the whole floorplan back and forth (rotating it's Z position) (it's supposed to be a ship over the ocean). For now, the ship will move back and forth, but some individual components like the fan vents and the windows move independently from the ship.

    What am I doing wrong?
     

    Attached Files:

  2. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    1,419
    Not terribly sure about your fan/vent setup, but if these have independent Animators and controllers, this is probably to be expected. :(

    I've never had any luck with these kinds of animations. Internally, each animated property tends to reference its own Animator stuff (it actually has its own address based on the gameobject name and animation layer). Thank Mecanim for the performance overhead and complexity. :/

    As an alternative -- I would rotate the floorlevel (root/parent) gameobject physically via script (rather than through Animation) -- This will let the things that have their own Animators (like fans) continue to reference their own animation while they are physically (inherently) rotated by the root gameobject/parent.
     
  3. apventures

    apventures

    Joined:
    Aug 6, 2018
    Posts:
    24

    Thanks for the tip! One of the methods i tried was to find a script that could simulate the movement and then I could modify it. The problem is that with many of the scripts I found and used, it still didn't matter. The fans still moved independently (even when I disabled their animation controllers). And the porthole windows still moved independently even though they never posessed controllers.

    Below is the current script I am using. I'm still not sure what I'm doing wrong. Another method I tried was exporting the whole GameObject level as .fbx to Maya, and then I grouped all of them into a merged mesh and exported them back to Unity. This didn't help. So now I'm back to square one.

    Code (CSharp):
    1. using System;
    2. using UnityEngine;
    3. public class RockShip : MonoBehaviour
    4. {
    5.     float originalY;
    6.     public float bobbingMultiplier = .5f;
    7.     public float rollMultiplier = .4f;
    8.     private Quaternion startRotation;
    9.     void Start()
    10.     {
    11.         originalY = this.transform.position.y;
    12.         startRotation = transform.rotation;
    13.     }
    14.     void Update()
    15.     {
    16.         BobUpAndDown( );
    17.         RollSideToSide( );
    18.         RollFrontToBack( );
    19.     }
    20.     void BobUpAndDown( )
    21.     {
    22.         transform.position = new Vector3(transform.position.x,
    23.                                          originalY + ((float)Math.Sin(Time.time) * bobbingMultiplier),
    24.                                          transform.position.z);
    25.     }
    26.     void RollSideToSide( )
    27.     {
    28.         float f = Mathf.Sin( Time.time * rollMultiplier ) * 10f;
    29.         transform.rotation = startRotation * Quaternion.AngleAxis( f, Vector3.forward );
    30.     }
    31.     void RollFrontToBack()
    32.     {
    33.         float f = Mathf.Sin(Time.time * rollMultiplier) * 2f;
    34.         transform.rotation = startRotation * Quaternion.AngleAxis(f, Vector3.left);
    35.     }
     
  4. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    1,419
    Are their colliders set to kinematic (assuming they have them)? -- You may have to foreach the child transforms (depending on your setup) if you want them to move as kinematic objects. Have you tried moving them individually (and do they move?) Try the script above separately on the fans by themselves (while in the hierarchy and outside too).
    I think FixedUpdate might be where you want to move them too if you're going the programmatic route.

    Just a few stabs in the dark.

    You should provide some gifs showing what's going on in your scene/animations, otherwise it's hard to pinpoint where the issue might be. Your screens don't help much.
     
  5. apventures

    apventures

    Joined:
    Aug 6, 2018
    Posts:
    24
    I tried adding the script to each of the fans and porthole objects. I also tried adding Mesh Colliders to each of the transforms for those objects. The attached gif shows that nothing has changed.
     

    Attached Files:

  6. apventures

    apventures

    Joined:
    Aug 6, 2018
    Posts:
    24
    Also, I'm not sure how to set as kinematic? Attached is a screenshot of how I have the fan node set up.
     

    Attached Files:

  7. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    1,419
    I forgot that "isKinematic" is no longer a thing -- I've been away from the programming side of Unity for a bit.

    Check your "Cooking Options" -- they could have something to do with the issue.
     
  8. apventures

    apventures

    Joined:
    Aug 6, 2018
    Posts:
    24
    I cycled through all of the cooking options for each piece of the fan meshes and porthole window meshes. Nothing has changed.
     
  9. apventures

    apventures

    Joined:
    Aug 6, 2018
    Posts:
    24
    So I tried deleting the porthole windows that are shifting around and I reimported their assets again.

    Strangely enough, that seems to have fixed them and now they move along with the rest of the ship. I just have to finish adding mesh rendering components to them so that they render the same as the other components (the porthole window models were originally modified in Maya and imported back into Unity for use, so that's why I have to set up their mesh rendering again).

    So the next step to is try re-importing the fans and see if that fixes their behavior.

    What's strange to me is that every piece of this ship/floorplan level was based off of an Asset package from the Asset store. I never modified the fans, only the windows by exporting them into Maya and modifying them into porthole windows when they were originally solid walls in the Asset package.

    I will report back if the fans still don't work.
     
  10. apventures

    apventures

    Joined:
    Aug 6, 2018
    Posts:
    24
    Update: Re-importing the fans also worked!

    So as it stands, the newly imported porthole windows and fan vents now rock with the boat without slipping or colliding strangely.

    The only strange part about it is that these components only work when they are *not* inside of the floorplan level hierarchy! When they are not made children of the floorplan level, they seem to work fine. This disaggregation is fine with me, as I don't need them to all be parented to the floorplan.

    On Monday I will be able to build it out and test it on the Oculus hardware to make sure that things are as they appear to be.

    But thank you for your help with narrowing it down! Hopefully this is the fix I needed.
     
    Last edited: Apr 19, 2019
    awesomedata likes this.
  11. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    1,419
    No problem! -- Glad I could still help a little! :)