Programmatically Changing SpringJoint

Hello,

I am trying to modify a H SpringJoint on my GameObject, but I cannot seem to find any way to reference it. I see there is a HingeJoint object on my GameObject, but this is set to null since I am using a SpringJoint, not a HingeJoint. If I added a HJ to my object, it is no longer null, but I need a SpringJoint.

I've searched through the answers here, and the docs, and still can't seem to find any way to access the values.

I appreciate any help!

GetComponent(SpringJoint).Damper ... for example, not work?

1 Answer

1
var h : float;

function Update () {
    GetComponent(SpringJoint).damper = h;
}

change the 'damper' to any of the following within the documentation http://unity3d.com/support/documentation/ScriptReference/SpringJoint.html

... or if you were looking to change the variables of a HingJoint.spring

var h : float;

function Update () {
    GetComponent(HingeJoint).spring.damper = h;
}

http://unity3d.com/support/documentation/ScriptReference/HingeJoint-spring.html

I might of misinterpreted what you were asking, but let me know if this helps.

Sure did. It appeared to me that GetComponent requires a name or tag, but simply doing object.GetComponent<SpringJoing>() worked. Thank you so much!