Search Unity

Is it possible to make something like this?

Discussion in 'Scripting' started by Paulx774, Sep 19, 2021.

  1. Paulx774

    Paulx774

    Joined:
    Mar 18, 2021
    Posts:
    103
    Is it possible to wield two objects together like in the image and move the sphere by rotating it, but keeping the cube's rotation fixed?



    Basically, I want to move the cube by rolling the sphere (kind of like one wheeled bike). I tried fixed joint, however, when the sphere rolls, the cube's rotation changes as well.

    Visualization of what I want:



    The both have rigidbodies and colliders, so I want physics interactions in the game. Snapping the cube's location to the sphere's location won't help me in terms of physics.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,697
    Are you making a Claptrap robot from Borderlands? :)

    The way you probably want to do this is to just have the cube separate from the ball (not parented), and drive its position to be the ball's position plus Vector3.up * spacing. This way the cube stays unrotated while the ball does whatever it wants.

    You would do this on the FixedUpdate() method to match physics update.

    Here is some timing diagram help:

    https://docs.unity3d.com/Manual/ExecutionOrder.html
     
  3. Paulx774

    Paulx774

    Joined:
    Mar 18, 2021
    Posts:
    103
    @Kurt-Dekker

    That would break the physics interactions with the object. Setting transform by hand means teleporting an object.

    Here's the visualization of your solution:



    The sphere can easily go under the white cube, however, it shouldn't. If I set the gray's cube location manually, the scenario in the image happens. The physics should be applied to them as if they are 1 object.

    I'm coming from Unreal Engine and I can do this type of thing by welding 2 objects together (like ragdoll) and they don't interact with each other, however, physics is applied to the whole object as if all of them (the gray cube and the sphere) are just 1 object. I was wondering if there's same type of feature in Unity to do this.
     
  4. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,411