Hi !
I have google this and can not found any answer to my problem.
I can’t find a way in JS to change spring joint values from a GameObject.
In the documentation, we can only access to hingeJoint.
Could someone explain me why ?
I tried
gameObject.springJoint.spring = value; fail;
gameObject.SpringJoint.spring = value; fail;
gameObject.rigidbody.springJoint.spring = value; fail;
gameObject.rigidbody.SpringJoint.spring = value; fail;
I can’t understand why hingeJoint can be accessed and modified so easily and why its not the same for other type of joint.
Any help will be appreciated.
Thanks.
private var springJoint;
function Start()
{
springJoint= GetComponent(SpringJoint);
}
function Update()
{
springJoint.blah = foo;
}
This is an automatic way, but you could expose the springJoint variable and probably drag it in. I haven’t tested any of this but I think it should work.
Sam, thank you for your input !
It worked great !
I used :
springJoint = gameObject.GetComponent("SpringJoint");
springJoint.spring = foo;
Thank you for your help !
1 Like
I wouldn’t use that code in an Update function or anything that has to be used many times, I believe GetComponent has quite a lot of overhead. Fetching it once and storing the reference in a variable is much faster for repeating code.
Yes, this is what i am doing actually.
I only store the variable during the Start.
And now i can modify the value of my spring with a GUI slider. It is very usefull.
Thank you again for your input.
Regards.