Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A balance question #3

Open
Eagleton opened this issue Jul 22, 2021 · 2 comments
Open

A balance question #3

Eagleton opened this issue Jul 22, 2021 · 2 comments

Comments

@Eagleton
Copy link

Thanks to your project, I duplicate a robot from your scene as a prefab.
But when none script used, the falling results seems to be different. In your scene, the robot falls stiffly, but in my scene, it falls softly and even the Calve.L collider embedded the Foot collider.
I can't find the reason

@sergioabreu-g
Copy link
Owner

Sorry, I don't understand what you mean. If you upload a video showing the difference between yours and mine I may be able to help you.

@Eagleton
Copy link
Author

The video: https://user-images.githubusercontent.com/37317459/126633958-717a5842-0223-4911-b93d-edb7159f287e.mp4

I imitated you and wrote a balance script and attached it to the test object. The purpose is to achieve STABILIZER_JOINT balance mode, and it becomes that effect.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Balance : MonoBehaviour
{

[SerializeField]
public struct JointDriveConfig
{
    //The same as the Angular Drive
    [SerializeField] private float positionSpring;
    [SerializeField] private float positionDamper;
    [SerializeField] private float maximumForce;
    public float PositionSpring { get { return positionSpring; } set { positionSpring = value; } }
    public float PositionDamper { get { return positionDamper; } set { positionDamper = value; } }
    public float MaximumForce { get { return maximumForce; } set { maximumForce = value; } }

    public static explicit operator JointDrive(JointDriveConfig config)
    {
        return new JointDrive
        {
            positionSpring = config.positionSpring,
            positionDamper = config.positionDamper,
            maximumForce = config.maximumForce
        };
    }

    public static explicit operator JointDriveConfig(JointDrive jointDrive)
    {
        return new JointDriveConfig
        {
            positionSpring = jointDrive.positionSpring,
            positionDamper = jointDrive.positionDamper,
            maximumForce = jointDrive.maximumForce
        };
    }

    public readonly static JointDriveConfig ZERO = new JointDriveConfig { positionSpring = 0, positionDamper = 0, maximumForce = 0 };

    public static JointDriveConfig operator *(JointDriveConfig config, float multiplier)
    {
        return new JointDriveConfig
        {
            positionSpring = config.PositionSpring * multiplier,
            positionDamper = config.PositionDamper * multiplier,
            maximumForce = config.MaximumForce * multiplier
        };
    }

}

public Rigidbody torso;

private GameObject stabilizerGameobject;
private Rigidbody stabilizerRigidbody;
private ConfigurableJoint stabilizerJoint;
private Quaternion targetRotation = Quaternion.identity;

[SerializeField] private JointDriveConfig stabilizerJointDrive;

public JointDriveConfig StabilizerJointDirve
{
    get { return stabilizerJointDrive; }
    set
    {
        if (stabilizerJoint != null)
            stabilizerJoint.angularXDrive = stabilizerJoint.angularXDrive = (JointDrive)value;
    }
}

// Start is called before the first frame update
void Start()
{
    stabilizerGameobject = new GameObject("Stabilizer", typeof(Rigidbody), typeof(ConfigurableJoint));
    stabilizerGameobject.transform.parent = torso.transform.parent;
    stabilizerGameobject.transform.rotation = torso.rotation;

    stabilizerJoint = stabilizerGameobject.GetComponent<ConfigurableJoint>();
    stabilizerRigidbody = stabilizerGameobject.GetComponent<Rigidbody>();
    stabilizerRigidbody.isKinematic = true;

    stabilizerJoint.connectedBody = torso;

    //get balance?
    stabilizerJointDrive.PositionSpring = 1000f;
    stabilizerJointDrive.PositionDamper = 50f;
    stabilizerJointDrive.MaximumForce = 800f;
    stabilizerJoint.angularXDrive = stabilizerJoint.angularYZDrive = (JointDrive)stabilizerJointDrive;
}

}
I don't know why the legs show such status.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants