- Home /
How do I edit springjoint components in script?
I'm trying to create a pickup script through the use of springjoints and have been trying to set the 'Connected Body' to an object, and detach it later via script, and I'm having trouble reading the docs.unity site. I'm also trying to do this to an object that has been raycasthit.
function FixedUpdate() {
if(Input.getbutton("e"))
{
var fwd = transform.TransformDirection (Vector3.forward);
var hit : RaycastHit;
if(Physics.Raycast(transform.position, fwd, hit, 2))
{
if(hit.collider.gameObject.tag == "Moveable")
{
var hitObject = hit.rigidbody;
hitObject.springJoint.
//Trying to find out how to get the springjoint component and connected body from the hit object. and set it to 'GameObject.Find("Spring Target")'
}
}
}
}
I don't understand how I get ahold of anything to do with springjoints via script, not to mention having it behave.
Grievemourne , other than your problem of finding the component,
I HAVE FOUND that it is very difficult to modify the QUALITIES of a spring joint, while a scene is running. This is even true just in the editor. It's an interesting problem.
It's not unlike how (generally) you can't "just move" a rigidbody in PhysX without whacky stuff happening. Springs only seem happy if they "start as they mean to go on"
notice for example this question
http://answers.unity3d.com/questions/368314/how-the-hell-do-you-game-pause-a-hinge-.html
and the linked question. Indeed pausing swinging saloon doors in Unity -- the blunt reality is I just don't know how to do it. I Cannot Do That.
BTW you have a singularly Gothic and depressing name, @Grievemourne!! that's straight out of a novel!! Or Byron or something ... eg, Some vapid shadow leads Grievemourne / to every falling place of loss.. (Or something like that.) (I don't actually know what "vapid" means.) Definitely a Gothic character name
Answer by whydoidoit · Dec 28, 2012 at 08:55 AM
You need to do:
var springJoint = hit.rigidbody.GetComponent(SpringJoint);