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

multiple objects in motion

Discussion in 'Scripting' started by Intruderxxx, Dec 18, 2013.

  1. Intruderxxx

    Intruderxxx

    Joined:
    Dec 11, 2013
    Posts:
    8
    I am not sure if this is the right section so i apologize ahead of time if this ins`t.

    I have two objects that sit one on top of the other . Both rigid objects both use gravity , no restrictions (yet )

    I want to be able to move the bottom object and the top object should move and rotate with the bottom one .
    There also need to be complete freedom on the objects (in case one of them hits something )so the other can keep moving .

    They cannot be linked as parent and child , because they have different proprieties and the top one is instantiated with materials and orientation .
    Any suggestions on how can i accomplish this ?

    Thanks
     
  2. marak-v1

    marak-v1

    Joined:
    Jul 7, 2013
    Posts:
    20
    You could put in the update of the 2nd object a modifier to its rotation based off the bottom ones.
     
  3. Intruderxxx

    Intruderxxx

    Joined:
    Dec 11, 2013
    Posts:
    8
    Yo mean to add a script and add update function that takes the orientation of the object below , and matches it ?
     
  4. marak-v1

    marak-v1

    Joined:
    Jul 7, 2013
    Posts:
    20
    Yup exactly, if its not connected but needa to match i do it this way.
     
  5. Eyeshock

    Eyeshock

    Joined:
    Sep 7, 2012
    Posts:
    60
    Last edited: Dec 18, 2013
  6. Intruderxxx

    Intruderxxx

    Joined:
    Dec 11, 2013
    Posts:
    8
    No joy the links in there dont seem to work and the OP didnt give the solution :(
    Well its pretty simple imagine having a car with an object on the roof , the object had different attributes , they need to move together and work together until something happens to the box , lets say car enters a low tunnel , box hits the wall , and needs to act differently than the car .
    It could also be that my approach is wrong please feel free to correct me if that is the case

    Would like some more options
    Thanks for the info, very much appreciated .
     
    Last edited: Dec 18, 2013
  7. Josh707

    Josh707

    Joined:
    Jul 12, 2012
    Posts:
    68
    Try making a physic material with the static friction really high and dynamic friction at 1, it may help to hold the box in place when the bottom one starts moving
     
  8. Intruderxxx

    Intruderxxx

    Joined:
    Dec 11, 2013
    Posts:
    8
    Thanks for the suggestion
    Tried , doesn`t work , it slides off when accelerating . it seems that i cant make the friction big enough to hold it in place .

    Another aproach is making a cage that limits the top object motion , but the tricky part is how can i interact with the object trough the cage ?
     
  9. guitarxe

    guitarxe

    Joined:
    Dec 1, 2013
    Posts:
    131
    What exactly are you trying to accomplish? If we use your example with the box and the truck, and if you want to use Unity's physics to accomplish this then you need to think a bit more about how it's done in real life (which is what Unity's physics tries to mimic). You wouldn't have the box simply sitting on the roof of the truck, it would just slide off from any sudden acceleration or deceleration. In real life, the box would be placed in the truck's trunk, which has borders to prevent the box from sliding off. Or it might be tied down with cables/ropes, or attached to the truck in some other manner. You could try to do the same in Unity, like you say yourself, a "cage".

    If you don't want to bother with all that, then what exactly is preventing you from writing a new behaviour where the box mimics the movement of the car? Several people have suggested this already, and you said in all cases simply that you either don't want to do it or it doesn't work, without any detail.
    What's stopping you from having this behaviour, and if your box should hit something like a bridge from your car example, then it's very simple to just check for this (or any) collision and should it occur then the method that keeps the box attached to the car would not be run any longer, allowing the box to continue with it's own movement unrelated to the car.
     
  10. Intruderxxx

    Intruderxxx

    Joined:
    Dec 11, 2013
    Posts:
    8
    Well , its seems you got the wrong impression , and the problem is that my example doesnt really resemble a car and object on top that was the bets description at the time .

    I am not trying to be an ass , i just dont know how to do it correctly , that why i am asking for help here .

    This is what i need : i have a platform that has boxes stacked up on it , the palyer can turn it and tilt it , and he can pull a box out , i need all the boxes to stay in their place , when the box is puled out the boxes on top of it will slide in the direction of the platform .

    Eyeshock posted a link wits some good suggestion , but they dont seem to exists anymore .

    Thanks for the help its appreciated .
     
  11. Deon-Cadme

    Deon-Cadme

    Joined:
    Sep 10, 2013
    Posts:
    288
    I think a few quick sketches would help a lot of people with understanding the behavior you want.

    But based on what I gather:
    1. you can move a box on the top freely
    2. moving a box below will move the box(es) above with it.
    3.you got a plane that they all stand on.
    3a. the plane can be moved/tilted etc and that makes all of the boxes on it move.

    Hm, I can also see different implementations depending on the results that you want.
    If you want the boxes to be unstable, like they slide and tumble all over the place then physics are the best way.
    If the objects should keep their local positions when they slide on the plane (example, the pyramid is not crashing down) when you tilt the plane, then a parent and child system is the best.

    That is just the basic way of thinking of course. You can mix these kinds of things... think on a game character with a ragdoll system that should drop his gear when he dies. The weapons, helmet etc is normally stuck to the character through the bone system (could be a parent child system as well if it was something else then a character).
    You would probably detach the objects that he wants to drop from the character and then initiate the physics based ragdoll on the character. The weapons would also fall in a natural way to the ground with the help of physics and collision system etc.

    Going back to your game, maybe the boxes are parent and child by default? You could use a collision check to see if they are touching any other boxes and form a parent and child relationship between them to make them move together. If the box is at the top of the pile is interacted with by the player, then you just detach it from the parent-child group that it belongs to. Then perform a new a new collision check from the box when you have placed it on a new location to see if it should connect with another object.
     
  12. Intruderxxx

    Intruderxxx

    Joined:
    Dec 11, 2013
    Posts:
    8
    cool ill try that and post bac the results .