Search Unity

Mimicking movement between two game objects?

Discussion in 'Getting Started' started by anfi0022, Feb 4, 2016.

  1. anfi0022

    anfi0022

    Joined:
    Jan 29, 2016
    Posts:
    5
    Hello ! I'm currently making a prototype for a puzzle game where you rotate the cube rather than the sphere. So the sphere is a rigid body object locked in x and z position so it stays on the cube while it rotates. My cube is a rigid body object with the player controller script from the roll a ball tutorial.This is how it looks right now and you rotate the cube with the wasd or arrow keys :

    Screenshot_2.png

    My problem comes when I try to design the mazes though. My goal is to make the mazes in Zbrush ( because it's faster and more intuitive than making them in Unity ) then import them and their collision into Unity as levels.
    Screenshot_1.png


    My problem is this now, Ideally i just want to replace my Cube mesh with the mesh from the obj file that i imported from Zbrush and the mesh-collider Unity makes from this . But you can't assign a mesh-collider to a rigid body object unless you check the is convex box which kind of creates bad collision. But it needs to be a rigid body object for me to use the player controller script from the roll a ball tutorial... (right?)

    How do I get around this? I tried making an empty game object with the mesh-collider I wanted in it. Then make a public game object variable in my player script where I reference this game object with my collision in it. Then since I can't use .AddTorque like i do on my rigid body cube object I tried something like this in Fixed update but I couldn't get it to work.

    //go is my public game object, in this case the object with my colision
    //rb.is my cube rigid body object with I control with my arrow keys or wasd
    // so every frame i get the transform from "rb" and assign it to my collision game object "go" so it mimics my cube's movement, or is this stupid and inefficient ?
    Transform trans = rb.transform;
    go.transform = trans;

    So since I can't use my mesh collider on my rigid body object which it has to be in order for me to control it ( right?) I was basically wondering how I could mimic the movement of my rigid body cube to my custom mesh colider game object. And is that the best way to do it or should I do it in another way?
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Not if you want them to actually work, I think. As you found, the best you can get with this is a non-convex mesh collider, which have a lot of limitations (for example, they don't collide with other non-convex mesh colliders).

    A good (efficient) maze would be a series of box colliders, or at least convex mesh colliders, and I don't know of any way to get that from something you design in Z-brush.

    So, my recommendation would be to give up this goal, as it conflicts with the goal of making a game that actually works. :)
     
    MikeTeavee likes this.
  3. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,144
    JoeStrout and MikeTeavee like this.
  4. anfi0022

    anfi0022

    Joined:
    Jan 29, 2016
    Posts:
    5
    Thanks for the pointers guys! Greatly appreciated.

    But as for the other option, to every frame copy the movement of my rigid body object and apply that to my mesh-collision object? How about that?

    Isn't there any (efficient / smart ) way to do that trough a script? Like maybe something like this

    void FixedUpdate ()
    {

    Transform trans = object1.transform;
    object2.transform = trans;

    }
    ?

    I mean Unity can make the collision well since it's just simple geometric shapes , if I just could copy the movement of my rigid body object to my collision object .... :)
     
  5. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    I'm afraid I don't understand. You generally put your colliders ON your rigid body; indeed, a rigidbody won't work without them. Why do you need to copy movements from one thing to another?
     
  6. anfi0022

    anfi0022

    Joined:
    Jan 29, 2016
    Posts:
    5
    Because I have the mesh-colider object with the collision on another object since I can't have it on my rigid body object. So if I could copy my movement of my Rigid body object every frame to my mesh-colision object my broblem would be solved :)
     
  7. Farelle

    Farelle

    Joined:
    Feb 20, 2015
    Posts:
    504
    you could try vector3.movetowards (or transform.movetowards) and set the time very short, so it's updating instantly.
    or maybe parent the object underneath since then it's automatically getting all the movement from it's parent.

    But then again, maybe it would help if you would tell why you can't have the mesh collider on your rigidbody object? cause to me it's reading as if you are using unity in a way it's not meant to.
     
    JoeStrout likes this.
  8. anfi0022

    anfi0022

    Joined:
    Jan 29, 2016
    Posts:
    5
    Well according to Unity 5 you can't have a non-convex MeshColider on a non-kinematic rigidbody object. I get the error below. And I need the object to be non-kinematic if I want to be able to rotate the object and calculate colision right? I get this when I try to make my mesh-colider a child of my controllable main object. And I can't make it convex since it kind of ruins the colision... :( How do I get around this?

    new 2.png
     
  9. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Well we've asked you several times now to back up and describe what it is you're trying to accomplish, in enough detail that we can understand. You haven't done that, so I don't see how we can help you.
     
  10. anfi0022

    anfi0022

    Joined:
    Jan 29, 2016
    Posts:
    5
    Ok, let me put it as clear as i can :
    Is there a way trough scripting to copy the movement from one game object to another? Without using parenting...
     
    Last edited: Feb 15, 2016
  11. Farelle

    Farelle

    Joined:
    Feb 20, 2015
    Posts:
    504
    ....you could try to just assign transform.position and transform.rotation from your object of choice to the other object.....but if you haven't figured that out yet, I'm wondering what are you doing to try to figure it out?
     
  12. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    @Farelle, it seems clear by now he's unwilling or unable to explain what he's doing. He's not interested in learning better approaches; he only wants to focus on this one (most likely incorrect) approach.

    (But yeah, you're right, copying the .position and .rotation of an object will indeed do what he's asking.)
     
  13. Farelle

    Farelle

    Joined:
    Feb 20, 2015
    Posts:
    504
    i wanted to give him a chance to explain himself :eek: because it's easy as experienced person to say that something is "easy" to figure out and maybe, just maybe his problem lies somewhere else...